Log4j - Separating log lines to multiple log files.

It’s generally good practise to partition the log lines of your java application into different log files based on functionality/module etc.

For eg. In a web application, we would want application log lines to be logged in to server.log, whereas information about remote user who made the requests to be logged into request.log.

This can be done by defining two appenders in log4j properties and configuring them to output to two different log files.

Here is the example log4j properties.

We have defined two appenders, fileAppender to output to server.log and requestAppender to output to requests.log. Only fileAppender is added to rootLogger, so any Logger instances created by passing java class will be logged to server.log.

Example code snippets showing how to log to server.log.

To log to requests.log the Logger instance should be created passing requestLogger as logger name.

Example code snippets showing how to log to request.log.


If you would like to embed code examples your blog like in this article, Try Doculet.


Continue reading...

Generating Key, CSR and Certificates for SSL

If you want to run your application in HTTPS mode, you will need to get SSL certificates from a valid CA (Certificate Authority) like Verisign.

In this post I will provide steps for generating private key, CSR (Certificate Signing Request) and importing signed certificate back to private key store using java keytool utility


Continue reading...

Spring - Reading values from file and injecting to bean property using SPEL

Sometimes you would need to inject value for spring bean property by reading values from a file. Good use case for this would be injecting passwords into bean property by reading value from a file rather than hard coding password into application context xml.

This can be done by creating property file with values we want to inject and use spring util properties to read values into application context as properties. Then, this property value can be injected using Spring SpEL.

To demonstrate this, lets pick example of initializing Jetty SslContextFactory with keystore file and key store password.


Continue reading...

Turning Knowledge into Intelligence and Creativity

What is difference between Knowledge, Intelligence and Creativity?

Knowledge is facts, information, and skills acquired by a person through experience or education by perceiving, discovering or learning.

Intelligence is using that knowledge in different contexts to invent new thoughts, new ideas, etc.

Creativity is using intelligence to create new work, new inventions etc.

Why mere knowledge is not enough?

Our education system is mostly designed around providing and evaluating knowledge acquired and undermines intelligence and curiosity. if we just keep accumulating knowledge without applying, it will get lost. We need to make knowledge easily accessible to be able gain the intelligence out of it. Let’s think about how knowledge is stored in memory to find out how we can retain knowledge.

How knowledge is stored in memory?

The brain contains dynamic connection of neurons. Anything we retain in memory create new connections or change existing connections in the brain. The things we learn generally get stored in short-term working memory. But brain has only limited space in short-term memory. Most things get discarded out of short-term memory.

We mostly use repetition technique to make items in short-term memory stay long enough. But the biggest problem with memorization through repetition is that it frequetly puts the information on just one connection. The brain always seeks meaning, patterns with exiting information to make more connections. The more ways you have to find a piece of information, the easier it is to retrieve.

How to improve your intelligence?

Whatever you learn, associate it with a meaning, associate it with a different contexts, associate it with similar things - don’t learn anything in isolation. This will make it retain in long-term memory. Then knowledge will be easily retrievable when you want to apply it. This can help with generating new ideas.

How to improve your creativity?

Creativity is “just connecting things.” - Steve Jobs

Creativity is using imagination to connect, stretch and merge things in new ways. To improve creativity we need to further expand connections of information in our brain so that it can be easily combined, transformed to create new ideas. Curiosity can help expanding connections and is the essential element for becoming more creative.

Curiosity is a lens through which you view everything around you. Without it,there are no adventures to be had, With it, there are enough for a million times - **Sean Patrick , Awakening your inner genius **

Curiosity will persuade you to seek interesting things, discover new information, explore related things.

Summary

We acquire knowledge through learning and experiences. Whatever you learn, try to associate it with as many things you can. Always learn with curiosity to expand your knowledge, expand your ideas. You will able to create something new.

Further Reading

If you are reading this post with curiosity, you would be interested in further reading on this topic. Here are some useful resources.


Continue reading...

Turning adversity into opportunity

The book Happiness Advantage suggests the trick to turn adversity into opportunity is to realize that there always exists a path that leads us from failure or setback to a place where we are even stronger and more capable than before the fall.

Things do not necessarily happen for the best, but some people are able to make the best out of things that happen - Tal Ben-Shahar

Success is more about using that downward momentum to propel ourselves in the opposite direction. It’s about capitalizing on setbacks and adversity to become even happier, even more motivated, and even more successful.


Continue reading...