Vertx logging

1,931 views
Skip to first unread message

Anil

unread,
Dec 18, 2015, 12:36:39 PM12/18/15
to vert.x

HI,

Following is appender and logger in  my log4j.xml for vertx package info logging. But log file is empty.

<appender name="vertx" class="org.apache.log4j.RollingFileAppender">
  <param name="append" value="true" />
  <param name="maxFileSize" value="100KB" />
  <param name="maxBackupIndex" value="5" />
  <param name="file" value="C:/logs/vertx.log" />
  <layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" />
  </layout>
</appender>
<category name="io.vertx.core">
    <priority value="info" />
     <appender-ref ref="vertx" />    
   </category>


i have set logger delegate factory to system properties in Application launcher before deploying the verticles

System.getProperties().put("vertx.logger-delegate-factory-class-name", "io.vertx.core.logging.SLF4JLogDelegateFactory");

Please let me know if you see any issues.

Thanks,
AK
 

Guido Medina

unread,
Dec 18, 2015, 12:50:46 PM12/18/15
to vert.x
Hi, if I'm not mistaken you also need this:

      <dependency>
         
<groupId>org.slf4j</groupId>
         
<artifactId>jul-to-slf4j</artifactId>
         
<version>1.7.13</version>
     
</dependency>

And whatever other bridge from Slf4j to Log4j

Hope that helps,

Guido.

Asher Tarnopolski

unread,
Dec 18, 2015, 12:56:49 PM12/18/15
to vert.x
two possible things:
1. if you wanna use log4j, you should use Log4jLogDelegeteFactory and not SLF4JLogDelegateFactory (no idea if there is a bridge provided by slf4j that lets you use log4 appenders, i never used is this way though) .
2. if you run vertx from command line/launcher, logger is initialized on vertx creation, before you System.getProperties().put() something in your verticles.
push your factory by system properties in your command line: java  -Dvertx.logger-delegate-factory-class-name=io.vertx....
if this doesn't help  - post a gist with your code here. 

Guido Medina

unread,
Dec 18, 2015, 1:05:30 PM12/18/15
to vert.x
Asher is right but the problem I faced is that Log4j2 -not Log4j- is not supported by that bridge so I had to use Slf4j and then bridge to Log4j2 which I would recommend over the old Log4j.

Asher Tarnopolski

unread,
Dec 18, 2015, 1:08:01 PM12/18/15
to vert.x
that's true guido. we're also using log4j2 and added it by creating dedicated Delegate and DelegateFactory for it.

Guido Medina

unread,
Dec 18, 2015, 1:11:52 PM12/18/15
to vert.x
For me wasn't a problem because Slf4j is in used by other dependencies and Log4j2 I have configured is with AsyncLoggers using LMAX so double bridge would only make few extra in a nano-second level call, the real gain is with the asynchronous and rolling random file appenders.

Guido Medina

unread,
Dec 18, 2015, 1:13:33 PM12/18/15
to vert.x
You can say my way is the lazy way, I raise my hand yes :D

Guido Medina

unread,
Dec 18, 2015, 1:15:38 PM12/18/15
to vert.x
Ideally -IMHO- what Vert.x team should is to move to Slf4j because it is widely used and bridges are already in place.

Alexander Lehmann

unread,
Dec 18, 2015, 6:57:59 PM12/18/15
to vert.x
I had some problems with slf4j in vertx when using maven (which is also using slf4j since 3.2 and gets the first pick to load a slf4j impl), so I ended up using log4j 1.2.

Anil

unread,
Dec 20, 2015, 2:29:19 AM12/20/15
to vert.x
HI All,

Thanks for reply.

you guys saying that slf4j-log4j not supported by vertx ? 

Regards,
Anil

Anil

unread,
Dec 20, 2015, 2:45:37 AM12/20/15
to vert.x
i have kept my log4j.xml in maven resources folder. Am I wrong ?

Alexander Lehmann

unread,
Dec 20, 2015, 4:29:29 AM12/20/15
to vert.x
slf4j-log4j should work if you have the dependencies in the maven project.

Alexander Lehmann

unread,
Dec 20, 2015, 4:32:40 AM12/20/15
to vert.x
What are you using to start the project? If you have a far-jar it should work, the src/main/resources files end up in the root of the classpath, which is correct.

If everything fails, I found that using -Dlog4j.debug=true gives usually good pointers what is wrong.

If it doesn't work, please put an example project up on github so we can take look.
Message has been deleted

Guido Medina

unread,
Dec 20, 2015, 10:53:36 AM12/20/15
to vert.x
Remember Log4j2 != Log4j
I would recommend you to use Log4j2

Anil

unread,
Dec 24, 2015, 11:22:34 PM12/24/15
to vert.x
i tried with debug as well, did not see any issues and logging not working.


Any help would be appreciated. In between, i will try log4j2. thanks.

Regards,
Anil

Anil

unread,
Dec 28, 2015, 10:02:46 PM12/28/15
to vert.x
Can some one look into this issue ? Thanks.

mathias

unread,
Dec 29, 2015, 12:48:40 PM12/29/15
to vert.x
Try to install the jul-to-slf4j-bridge as described at http://www.slf4j.org/api/org/slf4j/bridge/SLF4JBridgeHandler.html
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler
.install();




Alexander Lehmann

unread,
Dec 29, 2015, 8:08:37 PM12/29/15
to vert.x
It looks like the logging is working correctly, I get the following lines in /var/log/seachlog.log

2015-12-30 02:06:48 DEBUG LoggingTestVerticle:14 - start method
2015-12-30 02:06:48 DEBUG ApplicationLauncher:20 - deployed successfully

Jez P

unread,
Dec 30, 2015, 4:07:20 AM12/30/15
to vert.x
Anil, please provide a simple github project which demonstrates the problem, along with details of how you are running that project. In other words something a bit more concrete. It shouldn't take long to create, and it's likely to get you a quicker, better answer than fragments of log files and "tried this but it didn't work". Provide a fuller reproducer and you will get better results.

Alexander Lehmann

unread,
Dec 30, 2015, 6:04:04 AM12/30/15
to vert.x
I should add that I have removed the jul-to-slf4j dependency, which is not required in this case I assume and am running the project as fatjar with

java -Dvertx.logger-delegate-factory-class-name=io.vertx.core.logging.SLF4JLogDelegateFactory -jar target\vertx-logging-0.0.1-SNAPSHOT-fat.jar

Anil

unread,
Dec 30, 2015, 9:26:34 PM12/30/15
to vert.x
HI Jez and Alexabder,


log4j.xml :

<appender name="file" class="org.apache.log4j.RollingFileAppender">
  <param name="append" value="true" />
  <param name="maxFileSize" value="5MB" />
  <param name="maxBackupIndex" value="10" />
  <param name="file" value="/var/log/search.log" />
  <layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" />
  </layout>
</appender>
<appender name="vertx" class="org.apache.log4j.RollingFileAppender">
  <param name="append" value="true" />
  <param name="maxFileSize" value="5MB" />
  <param name="maxBackupIndex" value="10" />
  <param name="file" value="/var/log/vertx.log" />
  <layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" />
  </layout>
</appender>
<category name="io.vertx.core">
    <priority value="INFO" />
     <appender-ref ref="vertx" />    
  </category>
<root>
<level value="DEBUG" />
<appender-ref ref="file" />
</root>
i am using following command to run the project -


java -Dvertx.logger-delegate-factory-class-name=io.vertx.core.logging.SLF4JLogDelegateFactory -jar target\vertx-logging-0.0.1-SNAPSHOT-fat.jar


my logger statements appended to search.log. there was not issue in that. Following category is not working, vertx.log is empty.

<category name="io.vertx.core">
     <priority value="INFO" />
      <appender-ref ref="vertx" />     
   </category>


Please let me know if you have any questions. Thanks.

Regards,
Anil

Alexander Lehmann

unread,
Dec 31, 2015, 10:20:47 AM12/31/15
to vert.x
The explanation is quite simple, vertx does not log anything in your program that would end up in the vertx.log file.

Please add the following code to your logging verticle and you should see log entries:

  public void start(){
    logger
.debug("start method");
   
try {
     
Thread.sleep(10000);
   
} catch (InterruptedException ex) {}
 
}


This will trigger the thread block detector and give a log entry every second.

Anil

unread,
Jan 18, 2016, 8:38:01 AM1/18/16
to vert.x
Thanks.. i can see time out exception only in console appender but not on other appenders.

Alexander Lehmann

unread,
Jan 18, 2016, 1:21:01 PM1/18/16
to vert.x
I think there is no console appender defined in your project, the exception should end up in the vertx.log file only.
Reply all
Reply to author
Forward
0 new messages