`
wandejun1012
  • 浏览: 2719602 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

log4j 按着日滚动设置

 
阅读更多

 

里面含有日滚动的文件名配置,未经测试,有空再测!

 

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.

 

ref url:http://www.4ucode.com/Study/Topic/654190

分享到:
评论

相关推荐

    log4j按功能保存日志

    在“log4j按功能保存日志”的场景中,我们通常会利用Log4j的配置灵活性,将不同功能的日志分别写入不同的文件,以便于后期分析、排查问题和监控系统状态。 1. **Log4j基本概念** - **Logger**: 日志记录器,是Log4...

    AndroidStudio 使用log4j记录日志,按照大小定期滚动日志Demo

    这段代码设置了日志输出到控制台和文件,文件名为"app.log",并按文件大小1MB进行滚动,最多保留5个旧文件。 3. **使用log4android记录日志** 现在可以在代码中使用log4android记录日志了: ```java private ...

    tomcat下的log4j日志配置

    2. **配置全局 Log4j 属性文件**:在任意位置创建 `log4j.properties` 文件,并设置全局的日志级别、输出格式及存储路径等。通常会将该文件放置在 Tomcat 的 `conf` 目录下。 ```properties log4j.rootLogger=...

    log4j记录压缩日记

    6. **日志级别**:Log4j支持多种日志级别,如DEBUG、INFO、WARN、ERROR和FATAL,开发者可以根据需要设置不同级别的日志输出。 7. **日志过滤器**:除了日志级别控制外,还可以通过Filter组件进一步筛选日志信息,...

    log4j-1.2.16下载

    2. **日志分割**:为了便于管理和分析,可以配置Log4j按日期分割日志文件。 3. **日志归档**:使用RollingFileAppender可以自动滚动和归档旧的日志文件。 4. **性能考虑**:虽然Log4j提供了丰富的功能,但过多的...

    Log4j扩展的一个按天滚动的appender类,同时支持动态日志

    此外,用户还可以通过配置XML文件(通常是`log4j.properties`或`log4j.xml`)来定制`DayRollingFileAppender`的行为,比如设置日志文件路径、滚动策略、文件大小限制等。 总结来说,`DayRollingFileAppender`是`Log...

    log4j.properties(完整版) log4j.properties(精简版)

    - **设置Layout**:如`log4j.appender.stdout.layout=org.apache.log4j.PatternLayout`,并定义其模式`log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n`,决定日志的显示格式。...

    log4j实用配置扩展

    #### 四、log4j的核心组件 log4j的核心组件主要包括**Loggers(记录器)**、**Appenders(输出源)**和**Layouts(布局)**。 1. **Loggers (记录器)**:负责生成日志信息,并决定是否发送日志信息到Appenders。记录器...

    tomcat下用Log4j 按文件大小,生成catalina.out日志文件

    在这个配置中,`MaxFileSize`参数指定了单个日志文件的最大大小(5MB),一旦达到这个大小,Log4j会滚动日志并创建新的文件。`MaxBackupIndex`参数指定了最多保留的旧日志文件数量,这里设置为10,意味着系统会保留...

    apache-log4j-extras-1.2.17-API文档-中文版.zip

    赠送jar包:apache-log4j-extras-1.2.17.jar; 赠送原API文档:apache-log4j-extras-1.2.17-javadoc.jar; 赠送Maven依赖信息文件:apache-log4j-extras-1.2.17.pom; 包含翻译后的API文档:apache-log4j-extras-...

    Log4J完整说明和配置

    - `org.apache.log4j.RollingFileAppender`:滚动文件输出。 - `Threshold=ERROR`:只有错误级别的日志才会被记录。 - `File=rolling.log`:指定输出文件名。 - `Append=true`:追加方式写入。 - `MaxFileSize=10KB`...

    log4j使用教程(详解)

    **日志框架Log4j详解** 在Java编程中,日志记录是不可或缺的一部分,它用于追踪应用程序的运行状态,帮助开发者在出现问题时定位错误、调试程序。Log4j是一款广泛使用的开源日志框架,由Apache软件基金会开发。本文...

    log4j 1.2.17版本jar包

    Log4j 1.2.17中包括ConsoleAppender(控制台)、FileAppender(文件)、RollingFileAppender(滚动文件)等多种类型的Appender。 3. **Layout**: 格式化器,定义日志信息的输出格式。例如,SimpleLayout只显示消息...

    log4j-1.2.11jar和log4j.properties配置文件

    **四、使用Log4j进行日志记录** 在Java代码中,我们可以使用以下方式调用Log4j: ```java import org.apache.log4j.Logger; public class MyClass { private static final Logger logger = Logger.getLogger...

    log4j生成文件及文件夹

    在IT行业中,日志记录是系统监控和故障排查的关键环节,而Log4j则是Java开发中最常用的日志框架之一。本文将深入探讨如何利用Log4j生成动态的日志文件名以及动态创建文件夹,帮助开发者更好地管理和分析应用程序的...

    log4j 写多个日志文件,按照日期每天都记

    2. **使用DailyRollingFileAppender**:`DailyRollingFileAppender`是`log4j`提供的一种特殊Appender,它可以按照指定的时间间隔(通常是每天)滚动生成新的日志文件。我们可以通过以下配置设置每日滚动: ```...

    log4j详细配置说明

    ### Log4j 详细配置说明 #### 一、Log4j 简介与特性 在当前强调可重用组件的软件开发环境中,Apache 的 Log4j 为开发者提供了强大的日志管理工具。Log4j 不仅开源免费,还具备高度的灵活性与可配置性,支持多种...

    log4j配置和加载方法

    例如`log4j.appender.A2=org.apache.log4j.RollingFileAppender`,并且指定了文件路径、最大文件大小以及备份索引,以实现日志文件的滚动存储。 #### 日志级别与转换模式 日志级别包括`DEBUG`、`INFO`、`WARN`、`...

    Tomcat使用Log4j输出catalina.out日志

    这个文件是Log4j日志配置的核心,用于定义日志的输出格式、日志文件的滚动规则等。 2. 配置DailyRollingFileAppender:通过定义一个DailyRollingFileAppender,可以使得日志文件按照日期进行滚动,每天生成一个新的...

    log4j中文手册.pdf

    《log4j中文手册》是Java开发人员必备的参考资料,它详细介绍了log4j这个广泛使用的日志记录框架。Log4j是Apache软件基金会开发的一个开源项目,主要用于生成应用程序运行时的日志信息,帮助开发者进行调试、性能...

Global site tag (gtag.js) - Google Analytics