在Camel上下文中配置Log4j [英] Configure Log4j in Camel context

查看:124
本文介绍了在Camel上下文中配置Log4j的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以配置骆驼路线以将消息发送到特定的log4j记录器?例如,我有以下记录器:

Is it possible to configure a Camel route to send a message to a specific log4j logger? For example, I have the following logger:

<logger name="com.me.log.mylogger" additivity="false">
    <level value="debug" />
    <appender-ref ref="file_appender_messages" />
</logger>

file_appender_messages只是一个RollingFileAppender.

然后我尝试在我的Camel上下文中使用以下命令对其进行记录:

I then try to log it using the following in my Camel context:

<to uri="log:com.me.log.mylogger?level=INFO" />

但是它在命令行上输出,而不是在file_appender_messages中指定的日志文件:

But it outputs on the command line instead of the log file specified in file_appender_messages:

25-Oct-2012 11:46:44 org.apache.camel.processor.CamelLogger log
INFO: [MESSAGE BODY]

我希望能够使用不同的记录器来记录来自不同来源的消息.我可以在消息处理器中完成此操作,但理想情况下,可以在路由xml中进行配置.能做到吗?

I would like to be able to use dffferent loggers for messages from different sources. I could do it in my message processors but ideally it could be configured in the route xml. Can it be done?

推荐答案

我通过在我的应用程序XML文件中将Logger定义为Bean来解决了这个问题

I fixed this by defining the Logger as a Bean in my application XML file

<bean id="myLogger" class="org.apache.log4j.Logger" factory-method="getLogger">
    <constructor-arg value="com.me.log.mylogger"/>
</bean>

然后在我的路线中,当我要记录消息时,我只是将其定向到Bean上的相关方法

Then in my route, when I want to log the message I just direct it to the relevant method on the Bean

<to uri="bean:myLogger?method=info" />

这篇关于在Camel上下文中配置Log4j的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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