log4j sample configuration file (properties file)

前端 未结 6 914
孤街浪徒
孤街浪徒 2020-12-31 14:22

What is the easiest way to get started with log4j configuration?

6条回答
  •  鱼传尺愫
    2020-12-31 14:39

    In addition to some other answers, I would add a persistence appender since that's the greatest advantage of using logs over consoles and debuggers; when one can't run through the application code in real-time or the event already occurred.

    !/"path"/"filename" will write to root of filesystem. "path"/"filename" will write to path relative to classpath root.

    log4j.rootLogger = ALL, Console, default.file
    log4j.appender.default.file=org.apache.log4j.FileAppender
    log4j.appender.default.file.file={path}/{filename}
    log4j.appender.default.file.layout=org.apache.log4j.PatternLayout
    log4j.appender.default.file.layout.conversionPattern=%m%n
    
    log4j.appender.Console=org.apache.log4j.ConsoleAppender
    ...
    

提交回复
热议问题