Java log4j 2 RollingFile某些时候无法读取gz日志文件
如标题所述,RollingFile appender有时无法压缩日志文件,有时在存档文件夹中获取xxx.txt,有时获取xxx.gz,配置如下:Java log4j 2 RollingFile某些时候无法读取gz日志文件,java,logging,configuration,log4j,log4j2,Java,Logging,Configuration,Log4j,Log4j2,如标题所述,RollingFile appender有时无法压缩日志文件,有时在存档文件夹中获取xxx.txt,有时获取xxx.gz,配置如下: <RollingFile name="dev1Log" fileName="E:/test/logs/dev1Log.txt" filePattern="E:/test/logs/archived/$${date:yyyy-MM}/dev1Log.txt-%d{yyyy-MM-dd}-%i.txt.gz
<RollingFile name="dev1Log" fileName="E:/test/logs/dev1Log.txt"
filePattern="E:/test/logs/archived/$${date:yyyy-MM}/dev1Log.txt-%d{yyyy-MM-dd}-%i.txt.gz">
<PatternLayout pattern="%-5p:[%c.class(%c{1}.java:%L)] %m%n"/>
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="1 M"/>
</Policies>
<DefaultRolloverStrategy max="100"/>
</RollingFile>
请在配置的顶部设置
。这将在控制台上打印内部Log4j2调试日志。要解决此问题,请在翻滚期间发布控制台上打印的Log4j2内部状态消息
如果Windows上的多个进程使用相同的Log4j2配置,则翻转可能会失败。这不是Log4j2行为,但取决于操作系统。Windows不允许您删除另一进程正在使用的文件 常见原因是多个应用程序之间共享相同的Log4j2配置(记录到相同的日志文件)。这应该避免 在同一Web容器中运行的Web应用程序可能共享日志记录配置,但需要注意。有关详细信息,请参阅Log4j2用户手册 请在配置的顶部设置
。这将在控制台上打印内部Log4j2调试日志。要解决此问题,请在翻滚期间发布控制台上打印的Log4j2内部状态消息
如果Windows上的多个进程使用相同的Log4j2配置,则翻转可能会失败。这不是Log4j2行为,但取决于操作系统。Windows不允许您删除另一进程正在使用的文件 常见原因是多个应用程序之间共享相同的Log4j2配置(记录到相同的日志文件)。这应该避免 在同一Web容器中运行的Web应用程序可能共享日志记录配置,但需要注意。有关详细信息,请参阅Log4j2用户手册
2017-09-09 16:26:57,582 ContainerBackgroundProcessor[StandardEngine[Catalina]] T
RACE DefaultRolloverStrategy.purge() took 182.0 milliseconds
2017-09-09 16:26:57,582 ContainerBackgroundProcessor[StandardEngine[Catalina]] D
EBUG RollingFileManager executing synchronous FileRenameAction[E:\andro_web\log4
j\mlWebLogs\xxxdev1Log.txt to E:\andro_web\log4j\mlWebLogs\archived\2017-09\xxxd
ev1Log.txt-2017-09-09-100.txt, renameEmptyFiles=false]
2017-09-09 16:26:57,582 ContainerBackgroundProcessor[StandardEngine[Catalina]] E
RROR Unable to move file E:\andro_web\log4j\mlWebLogs\xxxdev1Log.txt to E:\andro
_web\log4j\mlWebLogs\archived\2017-09\xxxdev1Log.txt-2017-09-09-100.txt: java.ni
o.file.FileSystemException E:\andro_web\log4j\mlWebLogs\xxxdev1Log.txt -> E:\and
ro_web\log4j\mlWebLogs\archived\2017-09\xxxdev1Log.txt-2017-09-09-100.txt: 程序
無法存取檔案,因為檔案正由另一個程序使用。(Chinese means: The program can not access the file because the file is being used by another program.)