如何将 HornetQ 日志记录委托给 Slf4j
我希望将嵌入在我的应用程序中运行的 HornetQ 的所有日志记录委托给 slf4j。不幸的是任何尝试都失败了。我已经尝试
- 添加 jul-to-slf4j
- 安装桥
SLF4JBridgeHandler.install();
- 尝试了
Log4jLogDelegateFactory
(“hornetq-configuration.xml”通过
)org.hornetq.integration.logging.Log4jLogDelegateFactory - 编写了我自己的
LogDelegate 和
LogDelegateFactory
但无论我做什么,以下几行都不会被捕获:
13.07.2011 17:42:11 org.hornetq.core.logging.impl.JULLogDelegate warn
WARNUNG: AIO wasn't located on this platform, it will fall back to using pure Java NIO. If your platform is Linux, install LibAIO to enable the AIO journal
13.07.2011 17:42:11 org.hornetq.core.logging.impl.JULLogDelegate info
INFO: Using NIO Journal
13.07.2011 17:42:11 org.hornetq.core.logging.impl.JULLogDelegate info
INFO: Started Netty Acceptor version 3.1.5.GA-r1772
我错过了什么?
I want that all logging from HornetQ, which runs embedded in my application, is delegated to slf4j. Unfortunately any attempt failed. I allready tried
- added jul-to-slf4j
- installed the bridge
SLF4JBridgeHandler.install();
- Tried the
Log4jLogDelegateFactory
("hornetq-configuration.xml" via<log-delegate-factory-class-name>org.hornetq.integration.logging.Log4jLogDelegateFactory</log-delegate-factory-class-name>
) - Wrote my own
LogDelegate
andLogDelegateFactory
But whatever I do, the folloing lines are not catched:
13.07.2011 17:42:11 org.hornetq.core.logging.impl.JULLogDelegate warn
WARNUNG: AIO wasn't located on this platform, it will fall back to using pure Java NIO. If your platform is Linux, install LibAIO to enable the AIO journal
13.07.2011 17:42:11 org.hornetq.core.logging.impl.JULLogDelegate info
INFO: Using NIO Journal
13.07.2011 17:42:11 org.hornetq.core.logging.impl.JULLogDelegate info
INFO: Started Netty Acceptor version 3.1.5.GA-r1772
Anything I did miss?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我找到了一个完整的解决方案,我想与您分享。
我之前已经单独尝试过其中每一个,但是您必须结合其他答案中提到的一些技术。
org.hornetq.core.logging.Logger.setDelegateFactory(new Slf4jLogDelegateFactory());
我只是想知道为什么他们不能使用经过验证的日志机制,这样可以轻松交换记录器。
I found a complete solution that I want to share with you.
I have previously tried each of these on their own, but you have to combine some of the techniques mentioned in other answers.
<log-delegate-factory-class-name>yourpackage.Slf4jLogDelegateFactory</log-delegate-factory-class-name>
org.hornetq.core.logging.Logger.setDelegateFactory(new Slf4jLogDelegateFactory());
I'm just wondering why they can't use proven logging mechanisms, that make it easy to exchange a logger.
由于您正在运行嵌入式,请尝试在启动服务器之前添加以下代码:
org.hornetq.core.logging.Logger.setDelegateFactory(new YourOwnDelegateFactory())
您可能会收到一些使用旧委托的消息,直到服务器从配置。
Since you are running Embedded, try adding this code before you start the server:
org.hornetq.core.logging.Logger.setDelegateFactory(new YourOwnDelegateFactory())
You had probably a few messages using the old delegate until the server got it from the config.
在尝试此操作时,我还发现,当
HornetQServerImpl
初始化其静态日志时,它会在加载新的LogDelegateFactory
之前执行此操作,因此不要使用我在 hornetq 上指定的日志-configuration.xml 它使用 JULLogDelegateFactory 因此其日志直接输出到控制台。深入研究 HornetQ 的代码,我发现它在 Logger.initialise() 上初始化它,并且它还在其中查找名为“org.hornetq.logger-delegate-factory-class-”的系统属性name" 设置默认工厂,所以我用它来解决我的问题。
我已经使用 Spring 修复了这个问题:
When trying this, I also found that when
HornetQServerImpl
initialized its static log, it does so before loading the newLogDelegateFactory
so instead of using the one I'm specifying on the hornetq-configuration.xml it usesJULLogDelegateFactory
so its logs are directly output to the console.Diving on HornetQ's code I found that it initializes this on
Logger.initialise()
and that also there it looks for a System property named"org.hornetq.logger-delegate-factory-class-name"
to set the default factory, so I used that to fix my problem.I've fixed this using Spring: