Three Basic Concept:
Category:
you instantiate a category instance, you can call its various logging methods(such as debug, info, warn, error, fatal) to send your message to log.
Appender:
Different destinations the message is appended. for example, file, console, jdbc, etc.
Layout: In which format you want your logging message will be appended. SimpleLayout, HTMLLayout, PatternLayout
A file named log4j.properties should be created and placed in same classpath with your application which invokes the log API.
Patterns associated with MDC(mapped diagnositic context):
org.apache.log4j.MDC
-static void put(String key, Object o)
- MDC.put(“server”,”jaguar”);
- MDC.put(“test”,”myContext”);
In PatternLayout=%d %X{server} %X{test} //Be careful, X is case sensitive.
-static void remove(String key)