Wednesday, October 26, 2011

Log4j: NDC/MDC

Nested Diagnostic Context (NDC) and Mapped Diagnostic Context (MDC) are used in cases when we want to distinguish logs from multiple threads by marking each log with thread specific information. NDC and MDC provide possibility to store some contextual information for each thread. But there's a difference in the way they do it.

Each thread has it's own context. NDC uses stack for pushing information when entering thread's context and popping it when leaving that context. This information is attached to log and can be displayed by using '%x' Pattern Layout option.

MDC uses map to store context information. It means that there must be a unique key associated with each piece of thread information. The information is attached to log and can be displayed by using '%X{key}' Pattern Layout option, where the key is an association with a value in the map.

Here you can find Log4j Pattern Layout option's description:

Saturday, October 15, 2011

Friend's blog

You can also visit my friend's tech blogs and find some interesting information for you.

Roman Ivanov -
Daniil Lopatin -

Tuesday, October 11, 2011

How to use SLF4J with Log4j

Today I will show you how to use SLF4J with Log4j on a simple example.

Let's start with Log4j. First, download log4j library and add log4j-1.2.16.jar into classpath.

Create file, which will contain log4j configuration and put it into project. It may look like this:

log4j.rootLogger=DEBUG, A1
log4j.appender.A1.layout.ConversionPattern=[%c{1}][%p]: %m%n

Monday, October 10, 2011

Why I choose Linux...

There are a lot of debates about Windows and Linux. What is the best OS? Which one to use?...I won't answer these questions, because every person should make decisions on his own. I'll only share my experience in using both of these systems.

Two years ago I even couldn't imagine my life without Windows. At that time I, probably, knew nothing about Linux, except the word :) It was usually for me to re-install my system after a regular virus or this 'magic' blue screen...