Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vertx LoggerHandler not adding logback

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.

like image 892
Navneet Avatar asked Jul 15 '15 06:07

Navneet


2 Answers

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.

like image 55
jaguililla Avatar answered Nov 14 '22 22:11

jaguililla


I was able to get it to work by setting the VM options as such:

-Dvertx.logger-delegate-factory-class-name=io.vertx.core.logging.Log4jLogDelegateFactory

Then in my log4j.properties, I had to add this:

log4j.category.io.vertx = TRACE
like image 43
mateuscb Avatar answered Nov 14 '22 22:11

mateuscb