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

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

问题描述

是否可以配置 Camel 路由以将消息发送到特定的 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天全站免登陆