vertx LoggerHandler not adding logback

前端 未结 3 1459
执念已碎
执念已碎 2021-01-01 01:35

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         


        
3条回答
  •  不思量自难忘°
    2021-01-01 02:04

    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
    

    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.

提交回复
热议问题