我们说有以下配置
...
log4j.rootCategory=DEBUG, CONSOLE
log4j.logger.com.app.me.Myclass=FILE
....
我知道如何找到根类别appender CONSOLE
Logger rootLogger = Logger.getRootLogger();
Enumeration<Appender> appenders = rootLogger.getAllAppenders();
while(appenders.hasMoreElements()){
//....
}
但是,如何获得类级别的追加器?我尝试在MyClass
Logger classLogger= Logger.getLogger(Myclass.class);
Enumeration<Appender> appenders = classLogger.getAllAppenders();
while(appenders.hasMoreElements()){
//....
}
appenders
始终不包含appender。
答案 0 :(得分:1)
这样做
log4j.logger.com.app.me.Myclass=DEBUG, myappender
log4j.additivity.com.app.me.Myclass=false
log4j.appender.myappender=org.apache.log4j.DailyRollingFileAppender
log4j.appender.myappender.datePattern='-'dd'.log'
log4j.appender.myappender.File=log/mylog.log
log4j.appender.myappender.layout=org.apache.log4j.PatternLayout
log4j.appender.myappender.logfile.layout.ConversionPattern=%-6r %d{ISO8601} %-5p %40.40c %x - %m\n