log4j in my vert.x application

3,543 views
Skip to first unread message

Francesco Ficarola

unread,
Dec 28, 2013, 5:40:10 PM12/28/13
to ve...@googlegroups.com
Hi everyone,

I'm developing a vert.x application. Specifically, I'm using Java + Eclipse + Maven + Vert.x. I read that JUL is the preferred logging framework and that vertx.log is saved under /tmp (I'm a linux user). Actually, I'd like to use log4j and generate different logging files under a custom logs folder. How can I do that? The vert.x documentation says (http://vertx.io/manual.html#logging):
If you don't want to use the Vert.x provided logging facilities that's fine. You can just use your preferred logging framework as normal and include the logging jar and config in your module.
 So I've tried to include the log4j dependency into my pom.xml, copy the log4j.xml file in src/main/resources and define a logger variable in my Verticle class, but the console does not print anything... Where I'm doing wrong?

Thank you,
Francesco

Francesco Ficarola

unread,
Jan 4, 2014, 3:59:30 PM1/4/14
to ve...@googlegroups.com
Up... Does anyone know how I can solve?

Tim Fox

unread,
Jan 6, 2014, 7:36:48 AM1/6/14
to ve...@googlegroups.com
Have you tried specifying the logger factory system property on the command line when you execute mvn?
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Francesco Ficarola

unread,
Jan 6, 2014, 9:50:01 AM1/6/14
to ve...@googlegroups.com
Yes, I've tried several solutions:

MAVEN_OPTS="-Dorg.vertx.logger-delegate-factory-class-name=xxx" mvn vertx:runMod

and

mvn vertx:runMod -Dorg.vertx.logger-delegate-factory-class-name=xxx

where xxx is Log4jLogDelegateFactory.

Additionally, I've tried to use SLF4JLogDelegateFactory, and even in this case it doesn't work, but it returns the following message when using the second command solution:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation

Thank you,
Francesco

Norman Maurer

unread,
Jan 7, 2014, 7:57:51 AM1/7/14
to ve...@googlegroups.com
Do you have the project on github or so ?

JasonP

unread,
Jan 7, 2014, 8:11:10 AM1/7/14
to ve...@googlegroups.com
I had the same problem.  I added the log4j dependency to the pom.xml, and it wasn't enough to make it work.  To get log4j working in my application, I had to add log4j-1.2.17.jar to the vert.x-2.0.2-final/lib folder.  I also had to put my log4j.properties under vert.x-2.0.2-final/conf.  Being new to the jvm world, I'm guessing that this is a classpath issue... There's probably a right way to do this, but I haven't had the time to go chase it down.

Jason

Tim Fox

unread,
Jan 7, 2014, 11:06:55 AM1/7/14
to ve...@googlegroups.com
You should be able to try this out using the Maven archetype

Francesco Ficarola

unread,
Jan 7, 2014, 11:35:34 AM1/7/14
to ve...@googlegroups.com
As suggested by Tim Fox you can generate a project by using the Maven archetype and then try to use log4j.

@JasonP: thank you for your solution, let's see if other solutions will come or if it's a bug.

Francesco

Norman Maurer

unread,
Jan 8, 2014, 6:02:50 AM1/8/14
to ve...@googlegroups.com, Francesco Ficarola
I got it to work by using this:

➜  log4jtest  mvn vertx:runMod -Dorg.vertx.logger-delegate-factory-class-name=org.vertx.java.core.logging.impl.Log4jLogDelegateFactory -Dlog4j.configuration=file:./target/mods/me.normanmaurer.vertx\~log4jtest\~1.0-SNAPSHOT/log4j.properties

Will see if I can figure out why it not is be able to find the log4.properties without the property.

-- 
Norman Maurer

Francesco Ficarola

unread,
Jan 8, 2014, 8:27:40 AM1/8/14
to ve...@googlegroups.com, Francesco Ficarola, norman...@googlemail.com
Thank you Norman, this solution would be better. Let us know if you can completely solve that, thank you again!

Francesco

Norman Maurer

unread,
Jan 8, 2014, 8:37:38 AM1/8/14
to Francesco Ficarola, ve...@googlegroups.com
I’m right that you are trying logging via container.logger() and not trying to use Log4j directly ?
-- 
Norman Maurer

Francesco Ficarola

unread,
Jan 8, 2014, 8:39:28 AM1/8/14
to ve...@googlegroups.com, Francesco Ficarola, norman...@googlemail.com
Yes, you're right. I'm trying logging via container.logger().

Francesco

Francesco Ficarola

unread,
Jan 8, 2014, 8:40:38 AM1/8/14
to ve...@googlegroups.com, Francesco Ficarola, norman...@googlemail.com
Actually, I also tried to use Log4j directly, but I got the same result (didn't work).

Francesco

Francesco Ficarola

unread,
Jan 16, 2014, 9:51:45 PM1/16/14
to ve...@googlegroups.com, Francesco Ficarola, norman...@googlemail.com
Any news?

Thank you,
Francesco

Tim Fox

unread,
Jan 17, 2014, 1:09:34 AM1/17/14
to ve...@googlegroups.com
I'm not sure what's wrong with the solution that Norman outlined...

But, if you use the latest SNAPSHOT Maven plugin/template you can also put any stuff you want on the Vert.x *platform* classpath in a src/main/resources/platform_lib directory

Danny Kirchmeier

unread,
Jan 24, 2014, 1:14:38 AM1/24/14
to ve...@googlegroups.com, Francesco Ficarola, norman...@googlemail.com
Recap for the uninitiated: When vertx runs, it has a class loader for itself (the platform manager) and then each running module (http://vertx.io/mods_manual.html#module-classloaders). 

By putting log4j.xml file in src/main/resources, your configuration file lives on the module classpath. 

All calls to org.vertx.java.core.logging.impl.LoggerFactory.getLogger() run on the platform classpath. This applies to the vertx.logger(). Since it is running on the platform classpath, it can't find your log4j.xml/log4j.properties file

I'm unfamiliar with the maven plugin, so using the log4j.configuration property may be your only option. If you run vertx plainly, you can set the CLASSPATH environment variable to include your configuration.

--Danny

Yury Funikov

unread,
Jul 28, 2014, 8:33:00 AM7/28/14
to ve...@googlegroups.com, francesco...@gmail.com, norman...@googlemail.com
Seems everything works fine in case log4j.xml/log4j.properties file is put to src\main\resources\platform_lib dir
Reply all
Reply to author
Forward
0 new messages