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.
source to share
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.
source to share
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.
source to share