NetBean 6.8 配置log4j

首先,在类库中引入log4j.jar 和 commons-logging.jar这两个包,然后在NetBeans的src目录下的源包目录中创建两个属性文件

log4j.properties 和 commons-logging.properties,其内容可以参考如下:

log4j.properties:

##LOGGERS## #define a logger #log4j.rootLogger=DEBUG,console,file log4j.rootLogger=INFO,console,file ##APPENDERS## #define an appender named console,which is set to be a ConsoleAppender log4j.appender.console=org.apache.log4j.ConsoleAppender #define an appender named file,which is set to be a RollingFileAppender log4j.appender.file=org.apache.log4j.RollingFileAppender log4j.appender.file.File=d:/log.txt #set the log's size log4j.appender.file.MaxFileSize=1000KB log4j.appender.file.MaxBackupIndex=20 ##LAYOUTS## #assign a SimpleLayout to console appender log4j.appender.console.layout=org.apache.log4j.SimpleLayout #assign a PatternLayout to file appender log4j.appender.file.layout=org.apache.log4j.PatternLayout #For debug #log4j.appender.file.layout.ConversionPattern=[%-5p][%t][%C][%d{yyyy-MM-dd HH:mm:ss}]%m%n #For deployment log4j.appender.file.layout.ConversionPattern=[%-5p][%d{yyyy-MM-dd HH:mm:ss}]%m%n 

commons-logging.properties

##set Log as Log4j org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger 

如此一来,就可以在编码中使用log4j来输出日志了。

你可能感兴趣的:(netbean)