log4j create a new log file every day

来源:互联网 发布:电商html模板 仿淘宝 编辑:程序博客网 时间:2024/05/28 22:10

After I joined in new project, I realized log is very important. We can log in console or file. Here is to introduce a way to log in file without overwrite. It's really easy to use log4j.

# Define the root logger with appender filelog4j.rootLogger = DEBUG, FILE# Define the file appenderlog4j.appender.FILE=org.apache.log4j.rolling.RollingFileAppender# Set the name of the filelog4j.appender.FILE.rollingPolicy = org.apache.log4j.rolling.TimeBasedRollingPolicylog4j.appender.FILE.rollingPolicy.FileNamePattern = tweetError.%d{MM-dd-yyyy}.log#log4j.appender.FILE.File=tweeterror.log# Set the immediate flush to true (default)log4j.appender.FILE.ImmediateFlush=true# Set the threshold to debug modelog4j.appender.FILE.Threshold=info# Set the append to false, overwritelog4j.appender.FILE.Append=true# Define the layout for file appenderlog4j.appender.FILE.layout=org.apache.log4j.PatternLayoutlog4j.appender.FILE.layout.conversionPattern=%m%n

What you need to do is to copy the code in a log4j.propeties file and add log4j.jar into your project. Then you'll see it'll create a new file every day when error is logged.


原创粉丝点击