vertx LoggerHandler不添加logback [英] vertx LoggerHandler not adding logback

查看:435
本文介绍了vertx LoggerHandler不添加logback的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用LoggerHandler记录所有传入的请求。我正在使用logback.xml来指定appender。我正在设置日志记录的系统属性。

I am trying to use LoggerHandler to log all incoming requests. I am using logback.xml to specify appenders. I am setting system property for logging.

System.setProperty("org.vertx.logger-delegate-factory-class-name",
            "org.vertx.java.core.logging.impl.SLF4JLogDelegateFactory");

仍然在控制台中记录所有内容而不是文件。

Still it is logging everything in console not in file.

推荐答案

这适用于Vert.x 3.4.1:

This worked for me with Vert.x 3.4.1:

    import static io.vertx.core.logging.LoggerFactory.LOGGER_DELEGATE_FACTORY_CLASS_NAME;
    import io.vertx.core.logging.LoggerFactory;

    // ...

    setProperty (LOGGER_DELEGATE_FACTORY_CLASS_NAME, SLF4JLogDelegateFactory.class.getName ());
    LoggerFactory.getLogger (LoggerFactory.class); // Required for Logback to work in Vertx

关键是得到一个记录器,我猜是初始化Logging子系统,用来获取Logger的类似乎无关紧要,因为我尝试了两个不同的类。

The key is to get a logger, which I guess initializes the Logging subsystem, the class that you use to get a Logger seems irrelevant as I tried with two different ones.

我将这些行作为程序中的第一个来运行生产代码和测试在两种情况下都能正常工作。

I run these lines as the first ones of the program in production code and in the tests to work properly in both contexts.

这篇关于vertx LoggerHandler不添加logback的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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