使用log4j生成日志文件

配置文件

    log4j.rootLogger=info,A0  
    #info,A0 

    #log4j.logger.org.springframework=FATAL 
    #log4j.logger.org.hibernate=FATAL 

    # debug info 
    log4j.logger.stdout=info,A0  
    log4j.additivity.stdout=false  
    #log4j.appender.A0=org.apache.log4j.ConsoleAppender 
    log4j.appender.A0=org.apache.log4j.DailyRollingFileAppender  
    log4j.appender.A0.File=${catalina.home}/logs/gopLogs/out.log   
    log4j.appender.A0.DatePattern='_'yyyy-MM-dd  
    log4j.appender.A0.encoding=gb2312  
    log4j.appender.A0.layout=org.apache.log4j.PatternLayout  
    log4j.appender.A0.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c - %m%n  


    # debug info 
    log4j.logger.syslog=info,A1  
    log4j.additivity.syslog=false  
    #log4j.appender.A0=org.apache.log4j.ConsoleAppender 
    log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender  
    log4j.appender.A1.File=${catalina.home}/logs/gopLogs/sys.log   
    log4j.appender.A1.DatePattern='_'yyyy-MM-dd  
    log4j.appender.A1.encoding=gb2312  
    log4j.appender.A1.layout=org.apache.log4j.PatternLayout  
    log4j.appender.A1.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c - %m%n  

    #log4j.debug=DEBUG 
    log4j.logger.roomlog=info,A2  
    log4j.additivity.roomlog=false  
    log4j.appender.A2=org.apache.log4j.DailyRollingFileAppender  
    log4j.appender.A2.File=${catalina.home}/logs/gopLogs/roomlog.log   
    log4j.appender.A2.DatePattern='_'yyyy-MM-dd-HH  
    log4j.appender.A2.encoding=gb2312  
    log4j.appender.A2.layout=org.apache.log4j.PatternLayout  
    log4j.appender.A2.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c - %m%n  

调用

public class Logs {  
    /** * 普通输出,主要用于调试 */  
    public static final Logger logger_out = Logger.getLogger("stdout");  

    /** * 连接(登录,注册)日志,用于日志入库 */  
    public static final Logger logger_conn = Logger.getLogger("conn");  

    /** * 聊天室日志,用于日志入库处理 */  
    public static final Logger logger_roomlog = Logger.getLogger("roomlog"); 

原帖:http://blog.csdn.net/maosijunzi/article/details/17378767

你可能感兴趣的:(log4j)