gpt4 book ai didi

slf4j - 如何将 HornetQ 日志记录委托(delegate)给 Slf4j

转载 作者:行者123 更新时间:2023-12-02 07:10:21 26 4
gpt4 key购买 nike

我希望将嵌入在我的应用程序中运行的 HornetQ 的所有日志记录委托(delegate)给 slf4j。不幸的是,任何尝试都失败了。我已经试过了

  • 添加了 jul-to-slf4j
  • 安装了网桥 SLF4JBridgeHandler.install();
  • 尝试了 Log4jLogDelegateFactory (“hornetq-configuration.xml”通过 <log-delegate-factory-class-name>org.hornetq.integration.logging.Log4jLogDelegateFactory</log-delegate-factory-class-name> )
  • 我自己写的LogDelegateLogDelegateFactory

但是无论我做什么,都不会捕捉到以下行:

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

我错过了什么吗?

最佳答案

我找到了一个完整的解决方案,想与您分享。我之前已经单独尝试过其中的每一个,但你必须结合其他答案中提到的一些技术。

  • 您需要编写自己的 LogDelegate:
import org.hornetq.spi.core.logging.LogDelegate;import org.slf4j.Logger;import org.slf4j.LoggerFactory;public class Slf4jLogDelegate implements LogDelegate {    private final Logger logger;    public Slf4jLogDelegate(Class clazz) {        logger = LoggerFactory.getLogger(clazz);    }    @Override    public void debug(Object message) {        logger.debug(message.toString());    }    @Override    public void debug(Object message, Throwable t) {        logger.debug(message.toString(), t);    }    @Override    public void error(Object message) {        logger.error(message.toString());    }    @Override    public void error(Object message, Throwable t) {        logger.error(message.toString(), t);    }    @Override    public void fatal(Object message) {        logger.error(message.toString());    }    @Override    public void fatal(Object message, Throwable t) {        logger.error(message.toString(), t);    }    @Override    public void info(Object message) {        logger.info(message.toString());    }    @Override    public void info(Object message, Throwable t) {        logger.info(message.toString(), t);    }    @Override    public boolean isDebugEnabled() {        return logger.isDebugEnabled();    }    @Override    public boolean isInfoEnabled() {        return logger.isInfoEnabled();    }    @Override    public boolean isTraceEnabled() {        return logger.isTraceEnabled();    }    @Override    public void trace(Object message) {        logger.trace(message.toString());    }    @Override    public void trace(Object message, Throwable t) {        logger.trace(message.toString(), t);    }    @Override    public void warn(Object message) {        logger.warn(message.toString());    }    @Override    public void warn(Object message, Throwable t) {        logger.warn(message.toString(), t);    }}
  • 然后你需要编写工厂:
import org.hornetq.spi.core.logging.LogDelegate;import org.hornetq.spi.core.logging.LogDelegateFactory;public class Slf4jLogDelegateFactory implements LogDelegateFactory {    // Maybe caching of delegates makes sense?    @Override    public LogDelegate createDelegate(Class clazz) {        return new Slf4jLogDelegate(clazz);    }}
  • 然后将以下行添加到您的 hornetq-configuration.xml 中: <log-delegate-factory-class-name>yourpackage.Slf4jLogDelegateFactory</log-delegate-factory-class-name>
  • 最后,在启动嵌入式服务器之前添加以下行: org.hornetq.core.logging.Logger.setDelegateFactory(new Slf4jLogDelegateFactory());

我只是想知道为什么他们不能使用经过验证的日志记录机制,这样可以很容易地交换记录器。

关于slf4j - 如何将 HornetQ 日志记录委托(delegate)给 Slf4j,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6682189/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com