简体   繁体   English

Log4j 1和2-来自两个Log4J版本的自定义追加程序同时写入同一文件

[英]Log4j 1 and 2 - Custom appenders from two Log4J versions writing to the same file simultaneously

I want to migrate from Log4J 1.x to Log4J 2 but at the same time I want to keep Log4J to support any external features (jars) that use Log4J. 我想从Log4J 1.x迁移到Log4J 2,但同时我想保留Log4J以支持使用Log4J的任何外部功能(罐)。 There are custom appenders written in Log4J and so the appenders will be re-written according to Log4J2 using plugins. 有用Log4J编写的自定义附加程序,因此将使用插件根据Log4J2重新编写附加程序。 So two configuration files needs to be there to support each version and the logs from both versions need to be written to the same file with the same format as defined in the custom appenders. 因此,需要有两个配置文件来支持每个版本,并且两个版本的日志都必须以自定义附加程序中定义的相同格式写入同一文件。

I found that simultaneous writing of multiple appenders to the same file is possible within a version but is it possible for the appenders coming from two Log4J versions to write to the same file simultaneously? 我发现一个版本中可以将多个追加程序同时写入同一文件,但是来自两个Log4J版本的追加程序是否可以同时写入同一文件? If yes is it a recommended practice and please suggest an alternative if it is not recommended. 如果是,则建议您这样做,如果不建议,请提出其他建议。

It would be an unusual setup to use both Log4j2 and Log4j 1.2 (not the adapter but the actual implementation) to do logging for an application at the same time. 同时使用Log4j2和Log4j 1.2(不是适配器而是实际实现)来同时为应用程序进行日志记录是不寻常的。

Configuring both logging libraries to write to the same file adds even more risk. 将两个日志库配置为写入同一文件会增加更大的风险。 It might work, it might not. 它可能有效,但可能无效。 It is certainly not what these libraries were designed for. 这些库的设计目的当然不是。

I would not recommend such a setup. 我不建议这样的设置。

The safest thing to do would be to postpone your Log4j2 migration until your log4j 1.2 custom appenders have been ported to Log4j2. 最安全的做法是推迟Log4j2迁移,直到将log4j 1.2自定义附加程序移植到Log4j2。 Then use the Log4j2 implementation and the log4j-1.2-api-2.x adapter module for the external libraries that use the Log4j 1.2 API. 然后,将Log4j2实现和log4j-1.2-api-2.x适配器模块用于使用Log4j 1.2 API的外部库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM