log4j的MDC
- - 行业应用 - ITeye博客原文地址: http://blog.csdn.net/huxin1/article/details/5736227. NDC(Nested Diagnostic Context)和MDC(Mapped Diagnostic Context)是log4j种非常有用的两个类,它们用于存储应用程序的上下文信息(context infomation),从而便于在log中使用这些上下文信息.
log4j.rootCategory=error,stdout,R log4j.appender.R=org.apache.log4j.DailyRollingFileAppender log4j.appender.R.File=D:/ysstech/workspace/test/systemout/log log4j.appender.R.DatePattern=yyyy-MM-dd'.log' log4j.appender.R.layout=org.apache.log4j.PatternLayout log4j.appender.R.layout.ConversionPattern=wmf %d{yyyy-MM-dd HH:mm:ss} %p %C.%M(%L): %n %m%n log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=wuming %d{yyyy-MM-dd HH:mm:ss} %p %C.%M(%L): %n%m%n log4j.appender.wu=org.apache.log4j.ConsoleAppender log4j.appender.wu.Threshold=error log4j.appender.wu.layout=org.apache.log4j.PatternLayout log4j.appender.wu.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %p %C.%M(%L): %n%m%n
import org.apache.log4j.Logger; public class testLog { public static void main(String[] args) { Logger logger = Logger.getRootLogger();//获得rootCategory中定义的appender Logger logger1 = Logger.getLogger("wu"); logger.error("有病"); logger.info("你好"); } }