使用单个log4j2 xml文件配置log4j2和log4j [英] Configuring log4j2 and log4j using a single log4j2 xml file

查看:547
本文介绍了使用单个log4j2 xml文件配置log4j2和log4j的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将应用程序迁移到log4j 2,并已通过log4j2.xml对其进行了配置

I've migrated my application to log4j 2, and I've configured it via log4j2.xml

但是,我正在使用的某些库取决于log4j1.如果我使用以下命令运行该应用程序:

However, some of the libraries I'm using depend on log4j 1. If I run the application using:

-Dlog4j.configurationFile=path/to/log4j2.xml

log4j 1抱怨找不到配置文件.我正在使用由log4j 2,log4j-1.2-api-2.0-rc1.jar提供的log4j 1.x桥.可以使用单个log4j2.xml来配置两者吗?

log4j 1 complains about not finding a configuration file. I'm using the log4j 1.x bridge provided by log4j 2, log4j-1.2-api-2.0-rc1.jar. Is it possible to configure both using a single log4j2.xml?

我尝试过的另一种方法是同时配置log4j和log4j2:

An alternative I've tried is configuring both log4j and log4j2 together:

-Dlog4j.configurationFile=path/to/log4j2.xml -Dlog4j.configuration=path/to/log4j.xml

我关心的是我的日志记录配置文件和输出的碎片.我还担心log4j.xml和log4j2.xml之间可能的冲突.例如日志文件error.log配置为在log4j 1中使用FileAppender,在log4j 2中使用RollingFileAppender.

My concern is fragmentation of my logging configuration files and output. I'm also concerned about possible conflicts between log4j.xml and log4j2.xml. e.g. the logfile error.log is configured to use a FileAppender in log4j 1 and a RollingFileAppender in log4j 2.

有什么建议吗?

[note]

这是我看到的错误:

log4j:WARN No appenders could be found for logger (org.apache.activemq.util.ThreadPoolUtils).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

我正在使用的log4j 2版本是log4j 2.0 rc1.

The version of log4j 2 I'm using is log4j 2.0 rc1.

[answer]

好像activemq-5.8.0.jar与log4j 1捆绑在一起.解决方案是简单地在activemq之前加载log4j 1.x网桥.

Seems like activemq-5.8.0.jar was bundled with log4j 1. The solution was simply to load the log4j 1.x bridge before activemq.

推荐答案

我建议使用log4j2发行版中包含的log4j-1.2适配器.这样,任何编码为log4j-1.2 API的库都可以与log4j2一起使用,而无需进行任何代码更改.

I would recommend using the log4j-1.2 adapter that is included in the log4j2 distribution. That way, any libraries coded to the log4j-1.2 API will work with log4j2 without any code changes.

您的类路径应包括:

  • log4j-api-2.6.1.jar
  • log4j-core-2.6.1.jar
  • log4j-1.2-api-2.6.1.jar
  • log4j2.xml

您的课程路径应包括:

  • log4j-1.2.x.jar
  • log4j.properties或log4j.xml(无论如何,log4j2都将忽略它们)

另请参见 http://logging.apache.org/log4j/2.x/faq.html#which_jars

这篇关于使用单个log4j2 xml文件配置log4j2和log4j的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆