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)
博客介绍了Log4j的三个基本概念,包括Category可调用日志方法发送消息,Appender指定消息追加的目的地,Layout规定日志消息的追加格式。还提到需创建log4j.properties文件并置于调用日志API的应用程序类路径下,以及MDC相关模式的使用。
109

被折叠的 条评论
为什么被折叠?



