Can't get SLF4J to bind in Vert.x using mvn vertx:runMod

1,198 views
Skip to first unread message

Georg Grütter

unread,
Feb 27, 2014, 3:12:43 AM2/27/14
to ve...@googlegroups.com
Hi all,

I'm trying to integrate SLF4J in my Vert.x application and I can't get it to run properly using mvn vertx:runMod. I have created a fresh project with Maven using the io.vertx archetype. I then added logback-classic to the pom dependency with scope compile. The dependency tree shows that both the SLF4J api and the binding (logback-classic) are present. Here's the dependency tree:

[INFO] com.bosch:loggingPOC:jar:1.0-SNAPSHOT
[INFO] +- io.vertx:vertx-core:jar:2.1M3:provided
[INFO] |  +- org.slf4j:slf4j-api:jar:1.6.2:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.2.2:provided
[INFO] |  |  \- com.fasterxml.jackson.core:jackson-annotations:jar:2.2.2:provided
[INFO] |  +- com.fasterxml.jackson.core:jackson-core:jar:2.2.2:provided
[INFO] |  +- log4j:log4j:jar:1.2.16:provided
[INFO] |  \- io.netty:netty-all:jar:4.0.14.Final:provided
[INFO] +- io.vertx:vertx-platform:jar:2.1M3:provided
[INFO] +- io.vertx:vertx-hazelcast:jar:2.1M3:provided
[INFO] |  \- com.hazelcast:hazelcast:jar:2.6.3:provided
[INFO] \- ch.qos.logback:logback-classic:jar:1.1.1:compile
[INFO]    \- ch.qos.logback:logback-core:jar:1.1.1:compile


When running the module using mvn vertx:runMod, there are not logging outputs. The logger instance has the class org.slf4j.helpers.NOPLogger, which tells me that SLF4J wasn't able to find the logback binding. 


Running the same module with vertx runmod (after mvn package), works just fine, though. 


Can anyone provide a hint as to what I might be doing wrong, here? Might it be some maven plugin that uses another binding which prevents SLF4J to bind to logback?


Thanks in advance for your suggestions and cheers,

Georg

Tim Fox

unread,
Feb 27, 2014, 6:11:30 AM2/27/14
to ve...@googlegroups.com
Are you trying to use SLF4J with container.logger()? Or something else?

Georg Grütter

unread,
Feb 27, 2014, 8:02:01 AM2/27/14
to ve...@googlegroups.com

Are you trying to use SLF4J with container.logger()? Or something else?
I'm not using container.logger(). I instantiate a logger instance via the SLF4J LoggerFactory in a superclass to all the Verticles I have. 

Oren Shvalb

unread,
May 26, 2014, 3:03:17 AM5/26/14
to ve...@googlegroups.com
Hi,

I'm having the exact same problem, have you found a solution??

Thank you!

Alexander Lehmann

unread,
May 26, 2014, 6:38:28 AM5/26/14
to ve...@googlegroups.com
I have fiddled around a bit with the loggers available with vert.x, either with the container logger or instantiating the logger directly in my classes and it turned out a bit complicated due to class loading issues (where to put what) and where the configuration file has to be.

I'm not 100% sure what maven uses as logger implementation, but it looks like it is using something with slf4j so it may be that you have to configure slf4j inside maven and not in your project. I didn't quite get to bottom of this and ended up using log4j 1.2 directly.

If it is not working with maven, please try if it works when creating a fatjar and running that, this will at least make sure that you have the right dependencies included and nothing else.

If that all doesn't help, please create a minimal project showing the issue and put it on github or somewhere.

Oren Shvalb

unread,
May 26, 2014, 9:34:12 AM5/26/14
to ve...@googlegroups.com
Thank you Alexander, 

There is a good chance I will end up using Log4j too although I really would like to use Logback.

I'll update you if I have any progress...

Alexander Lehmann

unread,
May 26, 2014, 10:53:40 AM5/26/14
to ve...@googlegroups.com
I have done some tests with slf4j as the default logger in vert.x (container.logger()), since I was trying to track down a problem with the internal logger property and I think I got logback to work, but I'm not sure if it worked with Maven.

I'll search through my examples to see if I still have that lying around.

Alexander Lehmann

unread,
May 26, 2014, 4:45:42 PM5/26/14
to ve...@googlegroups.com
Ok,after checking my recent projects with log4j and slf4j, I found out how this works, at least partially.

I have no idea why slf4j logging doesn't work in maven 3.0, however it works in maven >=3.1 since that uses slf4j anyway. The logger implementation shipped with the newer maven is slf4j-simple, which means that your log messages will show up in the regular maven log according to this config (i.e. it doesn't show DEBUG messages etc).
You can easily swap the logging implementation inside maven by replacing the jars in $MAVEN_HOME/lib e.g. with logback, however that means that all of maven uses logback.

http://maven.apache.org/maven-logging.html

I don't think this is even a vert.x-specific issue, this will probably happen on anything that is started inside the maven processing by a plugin that uses slf4j.

If you use any other method of running the module, the problem will not happen, e.g. if you run a finshed module with vertx runMod.0

Trevor S

unread,
May 26, 2014, 5:15:02 PM5/26/14
to ve...@googlegroups.com
add the SLF4J jars and logging impl jars as dependencies (<dependency>) to the vertx-maven-plugin.

Trevor S

unread,
May 26, 2014, 5:19:17 PM5/26/14
to ve...@googlegroups.com
clarifing :

in your maven pom

<build>
   <plugins>
     <plugin>
        <artifactId>vertx-maven-plugin</artifactId> 
         ..
         ..
        <dependencies><dependency> logging deps

Alexander Lehmann

unread,
Jun 6, 2014, 8:19:51 PM6/6/14
to ve...@googlegroups.com
Is there an option to exclude jars used by maven from an invocation of a plugin?

To run slf4j with e.g. logback in maven 3.2, it would be necessary to disable slf4j-simple to get another working.

idlemind

unread,
Dec 13, 2014, 10:05:09 AM12/13/14
to ve...@googlegroups.com
Hello All,

Not quite sure what I'm missing. I'm able to see info logs on my eclipse consol but not the debug. Based on information provided on several threads, I've managed to update configuration in every logging.properties file but none seems to have worked.

Following are the steps I'v followed:
I've updated a logging.properties file in maven home: apache-maven-3.1.1\conf\logging
I've updated a logging.properties file in vertx conf directory: vertx\conf

One thread suggested that I add a dependency in my pom.xml as follows: 
<dependency> 
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-log4j12</artifactId>
  <version>1.7.7</version>
</dependency>

 But this has not worked either.


Could someone please guide me to the correct place where I can update a configuration to see debug logs.

Alexander Lehmann

unread,
Dec 13, 2014, 3:02:23 PM12/13/14
to ve...@googlegroups.com
I think you are not using SLF4J, but I'm only guessing here:

- logging.properties applies to the classpath (resp. conf dir) of vert.x logging (jul), this does not use slf4j, if you are running vertx with maven, the vertx directory is not used

- slf4j conf depends on the backend you use (log4j, simple, logback etc), but you have to select the backend in your project conf or at runtime, if you are using slf4j-log4j you have to provide a log4j conf file in the classpath, same problem as above, it has to fit the project

- vertx does not use an alternate logging implementation unless you select it in a property, so adding slf4j, log4j etc isn't doing anything

- in maven you get slfj4 issues starting with version 3.1 (or 3.2, I'm not sure) since they have switched from their own logging imp to slf4j, so you cannot change the configuration inside the runMod task in vert.x


The easiest solution to set the debug level is probably to put a logging.properties file into src/main/platform_lib and set everything there

To use slfj4, add a jvm property like this: http://vertx.io/manual.html#logging on maven run config and see which jars you need

Vikrant Rana

unread,
Dec 15, 2014, 12:38:35 AM12/15/14
to ve...@googlegroups.com
Thanks for a quick response Alexander, But the putting the logging.properties in src/main/platform did not log the debugs either.
Inline image 1

My logging configuraiton is as follows:
handlers=java.util.logging.ConsoleHandler,java.util.logging.FileHandler
java.util.logging.SimpleFormatter.format=%5$s %6$s\n
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
java.util.logging.ConsoleHandler.level=ALL
java.util.logging.FileHandler.level=ALL
java.util.logging.FileHandler.formatter=org.vertx.java.core.logging.impl.VertxLoggerFormatter

# Put the log in the system temporary directory
java.util.logging.FileHandler.pattern=%t/vertx.log

.level=ALL
org.vertx.level=ALL
com.hazelcast.level=ALL
io.netty.util.internal.PlatformDependent.level=ALL

Regards,

Vikrant S Rana

--
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/rLQ59QxzvTw/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,
Dec 17, 2014, 6:39:19 PM12/17/14
to ve...@googlegroups.com
Sorry, I got this wrong, putting logging.properties into platform_lib doesn't change anything, since the jul logging configuration happens at the start of the vm.

You can run maven with your own config file like this:

mvn vertx:runMod -Djava.util.logging.config.file=src/main/platform_lib/logging.properties

that works in eclipse as well

MT uulu

unread,
May 29, 2015, 10:04:04 AM5/29/15
to ve...@googlegroups.com
thanks Trevor! it worked for me.

bytor99999

unread,
May 29, 2015, 4:02:24 PM5/29/15
to ve...@googlegroups.com
I love resurrections.

Mark
Reply all
Reply to author
Forward
0 new messages