LOG4J 配置文件一段
log4j.rootLogger=ERROR,allerror,heartbeat
log4j.additivity.com.cvicse.inforguard=false
log4j.appender.allerror=org.apache.log4j.RollingFileAppender
log4j.appender.allerror.MaxFileSize=1024KB
log4j.appender.allerror.File=logs/mc.log
log4j.appender.allerror.layout=org.apache.log4j.PatternLayout
log4j.appender.allerror.layout.ConversionPattern=%d [%p] %c <%t> \n%m%n
log4j.logger.com.cvicse.inforguard = DEBUG, allerror
log4j.logger.com.cvicse.inforbroker = ERROR, allerror
log4j.logger.org.springframework = ERROR, allerror
log4j.logger.org.hibernate = ERROR, allerror
#ms heartbeat test
log4j.appender.heartbeat=org.apache.log4j.RollingFileAppender
log4j.appender.heartbeat.MaxFileSize=1024KB
log4j.appender.heartbeat.File=logs/pingHost.log
log4j.appender.heartbeat.layout=org.apache.log4j.PatternLayout
log4j.appender.heartbeat.layout.ConversionPattern=%d [%p] %c <%t> \n%m%n
log4j.logger.com.heartbeat= ERROR,heartbeat
#corba message with MA and SA
log4j.appender.corbamessage=org.apache.log4j.RollingFileAppender
log4j.appender.corbamessage.MaxFileSize=1024KB
log4j.appender.corbamessage.File=logs/message.log
log4j.appender.corbamessage.layout=org.apache.log4j.PatternLayout
log4j.appender.corbamessage.layout.ConversionPattern=%d [%p] %c <%t> \n%m%n
log4j.logger.com.corbamessage= DEBUG,corbamessage
定义allerror 给他指定com.cvicse.inforguard包下面的日志需要输出到mc.log文件中。
使用的时指定类名.class如下代码所示:
private static final Log m_log = LogFactory.getLog(GuardMessageHandler.class);
想监控com.cvicse包下面的指定类的日志到指定文件中。如上面log4j中所示:定义的corbamessage中指定了一个别名com.corbamessage
配置文件使用方式:log4j.logger.com.corbamessage=DEBUG,corbamessage
使用时getLog的参数指定在定义时com.corbamessage
private static final Log m_log = LogFactory.getLog("com.corbamessage");
下面代码为最普通的log4j的用法。使用时LogFactory.getLog(类名.class);
log4j.appender.guard =org.apache.log4j.RollingFileAppender
log4j.appender.guard.append=true
log4j.appender.guard.Threshold=DEBUG
log4j.appender.guard.bufferedIO=false
log4j.appender.guard.layout=org.apache.log4j.PatternLayout
log4j.appender.guard.layout.ConversionPattern=%d{ABSOLUTE} | %-5.5p | %-16.16t | %-32.32c{1} | %-32.32C %4L | %m%n
log4j.appender.guard.file=${utmp.base}/logs/utmp.log
log4j.appender.guard.append=true
log4j.appender.guard.MaxBackupIndex=2
log4j.appender.guard.MaxFileSize=50MB
log4j.logger.com.cvicse.inforguard=DEBUG,guard