The most recent version of this page is a draft.DiffThis version (2022/01/31 08:26) is a draft.
Approvals: 0/1
The Previously approved version (2021/12/28 17:00) is available.Diff

This is an old revision of the document!

How to use vert.x logging with Log4j and slf4j

Running vert.x with another logger tool looks easy, however I had a few problems getting this to work, after some reseach, some questions in the vert.x group (Thanks Tim), at least on bug fix by yours truly, it basically works.

First of all, whats the point

vert.x uses java.util.logging by default, which is quite ok for most use cases, however it doesn't support logging of class names, code locations etc, so a more fancy logging framework might be useful. There are many to choose from and everybody probably has their favorite, log4j, slf4j, logback, log4j2.

I personally usually use slf4j and log4j as backend for development (and simple logger for live systems, though I do not really have much of “live” things since we use other tools on my work projects), when running inside Eclipse, logback may be a good idea, somebody suggested log4j2 on the group.

Running in maven

   mvn package vertx:runMod

g4jLogDelegateFactory -Dlog4j.ignoreTCL=true

should work around an problem in maven causes an error

log4j:ERROR A “org.apache.log4j.ConsoleAppender” object is not assignable to a “org.apache.log4j.Appender” variable. log4j:ERROR The class “org.apache.log4j.Appender” was loaded by log4j:ERROR [ClassRealm[plugin>io.vertx:vertx-maven-plugin:2.0.5-final, parent: [email protected]]] whereas object of type log4j:ERROR “org.apache.log4j.ConsoleAppender” was loaded by [[email protected]a18817]. log4j:ERROR Could not instantiate appender named “stdout”.