本文备忘用,下面大部分引用log4j原文,也掺杂着我增加的示例。也方便大家学习参考。
log4j is possible to specify monthly, weekly, half-daily, daily, hourly, or minutely rollover schedules.
For example,
log4j.appender.fileout=org.apache.log4j.DailyRollingFileAppender
log4j.appender.fileout.File=./logs/programdolt.log
#log4j.appender.fileout.DatePattern='.'yyyy-MM-dd
log4j.appender.fileout.DatePattern='.'yyyy-MM-dd-HH-mm
org.apache.log4j
Class DailyRollingFileAppender
java.lang.Object
org.apache.log4j.AppenderSkeleton
org.apache.log4j.WriterAppender
org.apache.log4j.FileAppender
org.apache.log4j.DailyRollingFileAppender
All Implemented Interfaces:
Appender, OptionHandler
________________________________________
public class DailyRollingFileAppender
extends FileAppender
DailyRollingFileAppender extends FileAppender
so that the
underlying file is rolled over at a user chosen frequency.
The rolling schedule is specified by the DatePattern
option. This pattern should follow the SimpleDateFormat
conventions. In particular, you must
escape literal text within a pair of single quotes. A
formatted version of the date pattern is used as the suffix for the rolled file
name.
For example, if the File
option is set to /foo/bar.log
and the DatePattern
set to '.'yyyy-MM-dd
, on 2001-02-16
at midnight, the logging file /foo/bar.log
will be copied to /foo/bar.log.2001-02-16
and logging for 2001-02-17 will continue in /foo/bar.log
until it rolls over the next day.
Is
is possible to
specify
monthly, weekly, half-daily, daily, hourly, or minutely rollover schedules.
DatePattern
|
Rollover schedule
|
Example
|
'.'yyyy-MM
|
Rollover at the beginning of each month
|
At midnight of May 31st, 2002
/foo/bar.log
will be copied to
/foo/bar.log.2002-05
. Logging for the
month of June will be output to
/foo/bar.log
until it
is also rolled over the next month.
|
'.'yyyy-ww
|
Rollover at the first day of each week.
The first day of the week depends on the locale.
|
Assuming the first day of the week is
Sunday, on Saturday midnight, June 9th 2002, the file /foo/bar.log
will be copied to /foo/bar.log.2002-23
. Logging for the 24th week of
2002 will be output to
/foo/bar.log
until it is rolled over the next week.
|
'.'yyyy-MM-dd
|
Rollover at midnight each day.
|
At midnight, on March 8th, 2002,
/foo/bar.log
will be copied to
/foo/bar.log.2002-03-08
. Logging for the 9th day of March will be output to
/foo/bar.log
until it is rolled over the next day.
|
'.'yyyy-MM-dd-a
|
Rollover at midnight and midday of each
day.
|
At noon, on March 9th, 2002,
/foo/bar.log
will be copied to
/foo/bar.log.2002-03-09-AM
. Logging for the afternoon of the 9th will be output to
/foo/bar.log
until it is rolled over at midnight.
|
'.'yyyy-MM-dd-HH
|
Rollover at the top of every hour.
|
At approximately 11:00.000 o'clock on
March 9th, 2002,
/foo/bar.log
will be copied to
/foo/bar.log.2002-03-09-10
. Logging for the 11th hour of the 9th of March will be output to
/foo/bar.log
until it is rolled over at the beginning of the next hour.
|
'.'yyyy-MM-dd-HH-mm
|
Rollover at the beginning of every
minute.
|
At approximately 11:23,000, on March 9th,
2001,
/foo/bar.log
will be copied to
/foo/bar.log.2001-03-09-10-22
. Logging for the minute of 11:23 (9th of March) will be output to
/foo/bar.log
until it is rolled over the next minute.
|
Do not use the colon ":" character in anywhere in
the DatePattern
option. The text before the colon is interpeted as the
protocol specificaion of a URL which is probably not what you want.
分享到:
相关推荐
log4j按功能保存日志
log4j配置文件以及配置文件说明 包里有一个log4j配置文件 和一个配置详解
Log4j日志配置说明,Log4j日志配置说明Log4j日志配置说明,Log4j日志配置说明
tomcat下的log4j日志配置,给tomcat配置log4j有好几种方法,我知道的有: 一、tomcat级别的统一日志管理 二、每个webapp分别配置log4j
最近写的demo。安卓环境使用log4j 滚动日志。 实现数据format格式化传输记录日志内容。 非配置文件的方式
log4j中配置日志文件相对路径方法分析 方法一、 解决的办法自然是用相对路径代替绝对路径,其实log4j的FileAppender本身就有这样的机制,如:log4j.appender.logfile.File=${WORKDIR}/logs/app.log 其中“${...
log4j中DailyRollingFileAppender删除前N天日志 可配置maxBackupIndex参数 文件中包含测试工程以及源码
log4j2配置文件,按照文件大小划分日志,保存日期天数内的日志,指纹日志命名规则,日志输出等级等功能
tomcat6.0 配log4j日志的必须文件及配置过程 tomcat6-------lib | |--------tomcat-juli-adapters.jar | |--------log4j.jar | |--------log4j.properites | |----bin |--------tomcat-juli.jar 最后把log4...
每天生成一个log4j日志文件,如果只需要将最近一段时间内的日志文件保留,以前或更早的文件不用保留。例如只保留最近一周的日志,日志文件保留3天等等这些。。。通过这个jar包就可以实现。 log4j.properties文件在...
由公司的项目需要根据日期和文件大小切分log4j日志,所以实现来该appender。本人测试通过,并且在公司的其它项目中已有线上使用,暂时还没发现问题。本人代码有写得不好或者错误的地方,欢迎大家指正,谢谢!!!
本文档提供log4j配置相对路径三种方法:log4j.properties文件配置、xml文件配置和通过servlet初始化方式来配置,希望对大家有所帮助
主要介绍了SSM整合中的Log4j的配置详情,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
已经封装好,把log4j.appender.fileout=org.apache.log4j.Log4JDateAndSizeSplit 即可,其余和原api一样: log4j.appender.fileout.MaxFileSize=10240KB log4j.appender.fileout.MaxBackupIndex=20
logstash采集log4j日志发送到es配置文件,可以把日志根据日志级别区分开,一个级别一条日志是es中的一条数据
log4j 详细配置 log4j 详细配置 log4j 详细配置 log4j 详细配置
Log4j是Apache的一个开放源代码项目,通过使用Log4j,我们可以控制日志信息输送的目的地是控制台、文件、GUI组件、甚至是套接口服务器、NT的事件记录器、UNIX Syslog守护进程等;我们也可以控制每一条日志的输出格式...
使用log4j2实现日志数据脱敏
log4j配置文档log4j配置文档log4j配置文档log4j配置文档log4j配置文档log4j配置文档log4j配置文档log4j配置文档log4j配置文档log4j配置文档log4j配置文档log4j配置文档
Log4j采用分模块输出不同日志文件的配置