我正在研究一个项目,将日志记录从log4j 1.x转换为log4j 2.x。
对于滚动文件appender,我需要创建应该具有PID的文件名
其中附加了服务。对于 ex:
在log4j 1.x中,它定义为以下:
<appender name="FILE" class="com.app.util.log4j.RollingFileAppender ">
<param name="File" value="${app.home}/logs/@{pid}-app.log"/>
<appender />
现在,根据log4j 2.x文档,要实现相同的内容,我应该编写一个转换器
类型文件转换器的插件 doc 。
但是,我找不到任何细节,例如需要扩展哪个课程和任何细节
示例代码与文件转换器有关。
请帮助实现这一目标。提前致谢...!!!
谢谢,
I am working on a project to convert logging from log4j 1.x to log4j 2.x.
For Rolling File Appender I need to create filename that should have the pid of the
service appended in it. For Ex:
In log4J 1.x it is defined as below:
<appender name="FILE" class="com.app.util.log4j.RollingFileAppender ">
<param name="File" value="${app.home}/logs/@{pid}-app.log"/>
<appender />
Now, as per the log4j 2.x documentation, to achieve the same, I should write a Converter
plugin of type File Converter doc.
But, I am not able to find any details like which class needs to be extended and any
sample code related to File Converter.
Please help to achieve this goal. Thanks in advance...!!!
Thanks,
发布评论
评论(1)
您可以使用两种占位符来生成旧日志文件后生成旧日志文件的名称:
%键{...}
在“ FileConverter”类别中。 log4j2将旧的日志文件的创建日期和索引号传递给这些转换器。其中只有两个:日期模式%d {...}
(cf. source code> source code ) >%i (参见源代码),他们必须实现arraypatternconverter
。
$ {键:value}
,它无法访问上述两个值。由于JVM的进程ID不会随时间变化,因此您不需要模式转换器,并且:
app.base
andpid
。可以使用系统属性查找:javalookup
带有“ pid”属性(您可以利用processIdutil
进行此操作)并将修改后的版本pr到log4j2 project。There are two kinds of placeholders you can use to generate the name of the old log file after a rollover:
%key{...}
in the "FileConverter" category. Log4j2 passes the old logfile's creation date and index number to these converters. There are only two of them: the date pattern%d{...}
(cf. source code) and the index pattern%i
(cf. source code) and they must implementArrayPatternConverter
.${key:value}
, which don't have access to the two values mentioned above.Since the process id of the JVM does not change in time, you don't need pattern converters and:
app.base
andpid
are set, you can use the system properties lookup:JavaLookup
with a "pid" property (you can exploit theProcessIdUtil
to do it) and PR the modified version to the Log4j2 project.