Very simple log4j2 properties configuration file using Console and Rolling File appender

后端 未结 3 2105
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-01 21:54

I\'d like a log4j2 properties file configuration with a console and a rolling file appender using log4j2 that can be used different application. The log configuration should rot

3条回答
  •  不要未来只要你来
    2021-02-01 22:36

    Try this out:
    
    # Declare loggers
    name=LoggingConfig
    appenders=a_console, a_rolling
    rootLogger.level=info
    rootLogger.appenderRefs=ar_console,ar_rolling
    rootLogger.appenderRef.ar_console.ref=StdoutAppender
    rootLogger.appenderRef.ar_rolling.ref=DailyRollingAppender
    
    # Console logger
    appender.a_console.type=Console
    appender.a_console.name=StdoutAppender
    appender.a_console.layout.type=PatternLayout
    appender.a_console.layout.pattern=%d{ISO8601} [%t] %-5p (%F\:%L) - %m%n
    
    # File logger
    appender.a_rolling.type=RollingFile
    appender.a_rolling.name=DailyRollingAppender
    appender.a_rolling.layout.pattern=%d{ISO8601} [%t] %-5p (%F\:%L) - %m%n
    
    appender.a_rolling.fileName=log4j2-sample.log
    appender.a_rolling.filePattern=log4j2-sample-%d{yyyy-MM-dd}.log
    
    appender.a_rolling.layout.type=PatternLayout
    appender.a_rolling.policies.type=Policies
    appender.a_rolling.policies.time.type=TimeBasedTriggeringPolicy
    appender.a_rolling.policies.time.interval=1
    

提交回复
热议问题