How to use log4j 2 in vertx

2,370 views
Skip to first unread message

Anindya Chatterjee

unread,
Apr 6, 2014, 1:09:37 PM4/6/14
to ve...@googlegroups.com
I want to use log4j 2.x as a default logger for vertx. But like log4j there is no LogDelegateFactory for log4j2 in vertx, so I created one looking at the source code for Log4jLogDelegateFactory. I put it in a separate library and referencing it in my vertx project. But problems come when I try to run "mvn vertx:runMod -Dorg.vertx.logger-delegate-factory-class-name=com.dizitart.logging.Log4j2LogDelegateFactory". I am getting below maven error:

[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building vertx-restful 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- vertx-maven-plugin:2.0.5-final:runMod (default-cli) @ vertx-restful ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.346s
[INFO] Finished at: Sun Apr 06 22:30:06 IST 2014
[INFO] Final Memory: 11M/121M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal io.vertx:vertx-maven-plugin:2.0.5-final:runMod (default-cli) on project vertx-restful: Execution default-cli of goal io.vertx:vertx-maven-plugin:2.0.5-final:runMod failed: An API incompatibility was encountered while executing io.vertx:vertx-maven-plugin:2.0.5-final:runMod: java.lang.ExceptionInInitializerError: null
[ERROR] -----------------------------------------------------
[ERROR] realm =    plugin>io.vertx:vertx-maven-plugin:2.0.5-final
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/C:/Users/1E/.m2/repository/io/vertx/vertx-maven-plugin/2.0.5-final/vertx-maven-plugin-2.0.5-final.jar
[ERROR] urls[1] = file:/C:/Users/1E/.m2/repository/io/vertx/vertx-platform/2.1RC3/vertx-platform-2.1RC3.jar
[ERROR] urls[2] = file:/C:/Users/1E/.m2/repository/io/vertx/vertx-core/2.1RC3/vertx-core-2.1RC3.jar
[ERROR] urls[3] = file:/C:/Users/1E/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.2.2/jackson-databind-2.2.2.jar
[ERROR] urls[4] = file:/C:/Users/1E/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.2.2/jackson-annotations-2.2.2.jar
[ERROR] urls[5] = file:/C:/Users/1E/.m2/repository/io/netty/netty-all/4.0.18.Final/netty-all-4.0.18.Final.jar
[ERROR] urls[6] = file:/C:/Users/1E/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.2.2/jackson-core-2.2.2.jar
[ERROR] urls[7] = file:/C:/Users/1E/.m2/repository/log4j/log4j/1.2.16/log4j-1.2.16.jar
[ERROR] urls[8] = file:/C:/Users/1E/.m2/repository/io/vertx/vertx-hazelcast/2.1RC3/vertx-hazelcast-2.1RC3.jar
[ERROR] urls[9] = file:/C:/Users/1E/.m2/repository/com/hazelcast/hazelcast/2.6.7/hazelcast-2.6.7.jar
[ERROR] urls[10] = file:/C:/Users/1E/.m2/repository/org/apache/maven/plugin-tools/maven-plugin-tools-api/3.2/maven-plugin-tools-api-3.2.jar
[ERROR] urls[11] = file:/C:/Users/1E/.m2/repository/org/codehaus/plexus/plexus-utils/3.0/plexus-utils-3.0.jar
[ERROR] urls[12] = file:/C:/Users/1E/.m2/repository/junit/junit/3.8.1/junit-3.8.1.jar
[ERROR] urls[13] = file:/C:/Users/1E/.m2/repository/org/apache/maven/plugin-tools/maven-plugin-tools-annotations/3.2/maven-plugin-tools-annotations-3.2.jar
[ERROR] urls[14] = file:/C:/Users/1E/.m2/repository/org/apache/maven/plugin-tools/maven-plugin-annotations/3.2/maven-plugin-annotations-3.2.jar
[ERROR] urls[15] = file:/C:/Users/1E/.m2/repository/org/codehaus/plexus/plexus-component-annotations/1.5.5/plexus-component-annotations-1.5.5.jar
[ERROR] urls[16] = file:/C:/Users/1E/.m2/repository/asm/asm/3.3.1/asm-3.3.1.jar
[ERROR] urls[17] = file:/C:/Users/1E/.m2/repository/asm/asm-commons/3.3.1/asm-commons-3.3.1.jar
[ERROR] urls[18] = file:/C:/Users/1E/.m2/repository/asm/asm-tree/3.3.1/asm-tree-3.3.1.jar
[ERROR] urls[19] = file:/C:/Users/1E/.m2/repository/org/codehaus/plexus/plexus-archiver/2.1.1/plexus-archiver-2.1.1.jar
[ERROR] urls[20] = file:/C:/Users/1E/.m2/repository/org/codehaus/plexus/plexus-io/2.0.3/plexus-io-2.0.3.jar
[ERROR] urls[21] = file:/C:/Users/1E/.m2/repository/com/thoughtworks/qdox/qdox/1.12.1/qdox-1.12.1.jar
[ERROR] urls[22] = file:/C:/Users/1E/.m2/repository/org/slf4j/slf4j-api/1.7.2/slf4j-api-1.7.2.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import  from realm ClassRealm[maven.api, parent: null]]
[ERROR]
[ERROR] -----------------------------------------------------: Error instantiating transformer class "com.dizitart.logging.Log4j2LogDelegateFactory"
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginContainerException

But this error does not occur when I am using default JUL logger. Any idea how to use my own logger implementation?

Regards,

Anindya Chatterjee

Alexander Lehmann

unread,
Apr 6, 2014, 2:25:28 PM4/6/14
to ve...@googlegroups.com
I assume that this cannot be resolved without looking at the source, can you maybe put the source up on a gist?

OTOH, you could use the slf4j binding for log4j2, that should work directly.

Anindya Chatterjee

unread,
Apr 6, 2014, 2:52:45 PM4/6/14
to ve...@googlegroups.com
Thanks for the reply. Here is the gist: https://gist.github.com/anidotnet/10010031
[ERROR] urls[20] = file:/C:/Users<span styl
...

Alexander Lehmann

unread,
Apr 6, 2014, 5:17:00 PM4/6/14
to ve...@googlegroups.com
Looks like maven is not including the jar for log4j2, it is including log4j 1.2, but that isn't compatible.

Sorry, didn't notice that before, your java classes look ok.



On Sunday, April 6, 2014 7:09:37 PM UTC+2, Anindya Chatterjee wrote:

Anindya Chatterjee

unread,
Apr 6, 2014, 11:21:37 PM4/6/14
to ve...@googlegroups.com

So what can be done to make maven include log4j2 jars? I already declared the log4j2 jars as maven dependency in my project, but still it is not including the same!

Thanks for the response..

Regards,
Anindya Chatterjee

--
You received this message because you are subscribed to a topic in the Google Groups "vert.x" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vertx/8_KYu1sDgd8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vertx+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alexander Lehmann

unread,
Apr 7, 2014, 4:28:30 PM4/7/14
to ve...@googlegroups.com
This is not working for some reason, but I don't know why.

When you do mvn package, the log4j2 jars end up in the lib directory, but the classes are not found by the vertx runzip command, when running mvn vertx:runMod, the classes are not yet present in the classpath when the exception happens.

I think you have to ask somebody who is more knowledgeable about class loading than me, sorry.

You could try the route via slf4j implementation of log4j2, but I assume you will get similar class load problems.

שחר בונדרמן

unread,
Apr 23, 2014, 6:54:36 AM4/23/14
to ve...@googlegroups.com
create a jar with those 2 classes and put the jar manually in platform lib dir.
[ERROR] urls[19] = file:/C:/Users/1E/.<spa
...

Alexander Lehmann

unread,
Apr 23, 2014, 3:18:35 PM4/23/14
to ve...@googlegroups.com
For some reason that doesn't work for me in gradle, the only way I can get log4j2 to work is to put the libraries directly into CLASSPATH and include the build/classes/main directory.
...
Reply all
Reply to author
Forward
0 new messages