Log4j2的RollingFileAppender详解

RollingFileAppender:实现日志文件自动更新

当满足条件(日志大小、指定时间等)重命名打包原日志文件进行归档,生成新日志文件用于日志写入。

参数 Type Description
name String The name of the Appender.
fileName String The name of the file to write to. If the file, or any of its parent directories, do not exist, they will be created.
filePattern String The pattern of the file name of the archived log file.
createOnDemand boolean 当该属性设置为true时,Log4j将根据需要(即首次有日志事件需要写入时)创建指定的日志文件,而不是在应用程序启动时立即创建。. Defaults to false.
xml 复制代码
    <appenders>
        <RollingFile name="SIZE_BASED_TRIGGERING"
                     fileName="${LOG_HOME}/${FILE_NAME}.log"
                     filePattern="${LOG_HOME}/${FILE_NAME}_%d{yyyy-MM-dd}_%i.log.gz" 
                     createOnDemand="true">
        </RollingFile>
    </appenders>
相关推荐
圆山猫1 天前
[Virtualization](四):Linux KVM/RISC-V 的 vCPU 运行路径
java·linux·risc-v
微学AI1 天前
一根针指向所有方向:挂谷猜想对 LLM Agent 技能-记忆架构的启示
开发语言·人工智能·架构·挂谷猜想
城管不管1 天前
ReAct、Plan-and-Execute、Reflection 三大智能 Agent 范式核心区别
java·人工智能·算法·spring·ai·动态规划
IT小白杨1 天前
从环境制备到自动化工作流:多账号运营的工程化架构拆解
java·经验分享·自动化·安全架构·指纹浏览器
豆瓣鸡1 天前
算法日记 - Day3
java·开发语言·算法
萧瑟余晖1 天前
Java深入解析篇九之NIO详解
java·网络·nio
韭菜炒鸡肝天1 天前
VTK开发笔记(一):VTK介绍,Qt..+VSx+VTK.编译
开发语言·笔记·qt
The Chosen One9851 天前
高进度算法模板速记(待完善)
java·前端·算法
Aaron - Wistron1 天前
Web API C# (Furion版)带 单元测试
开发语言·后端·c#
Dxy12393102161 天前
Python项目打包成EXE完整教程(PyInstaller实战避坑)
开发语言·python