Vertx LoggerHandler does not add login

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

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

      

However, it writes everything to the console, not to a file.

+6


source to share


3 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 getting the logger, which I think initializes the logging subsystem, the class you are using to get the logger seems out of place as I tried with two different ones.

I am running these lines as the first of the programs in production code and in tests to work fine in both contexts.

+5


source


I managed to get it working 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 the following:

log4j.category.io.vertx = TRACE

      

+2


source


I know this question is a little out of date, but the only way I could get vertx LoggerHandler

not to use JUL is to call it LoggerFactory.initialise()

after setting the system property as described in the question.

Moreover, I have set the property in my build.gradle like this:

run {
  systemProperty(
    "vertx.logger-delegate-factory-class-name",
    "io.vertx.core.logging.SLF4JLogDelegateFactory"
  )
  args = ['run', mainVerticleName, "--redeploy=$watchForChange", "--launcher-class=$mainClassName", "--on-redeploy=$doOnChange",
          "-Dvertx.logger-delegate-factory-class-name=io.vertx.core.logging.SLF4JLogDelegateFactory" ]
}

      

And then at the very stop of my MainVerticle::start

me there is:

LoggerFactory.initialise()

      

And, boom. Everything is now formatted correctly, including all startup output.

0


source







All Articles