Besides the logback JAR files, you'll need to grab the latest SLF4J libraries as well from http://slf4j.org/. Below are the JAR files required to get logback working:
- logback-core-1.0.0.jar
- logback-classic-1.0.0.jar
- slf4j-api-1.6.4.jar
SLF4J: The requested version 1.6 by your slf4j binding is not compatible with [1.5.5, 1.5.6]On to the logback.xml configuration file. It's a very basic configuration. Just two appenders: STDOUT and SYSLOG. SYSLOG appender is the one we're interested in.
SLF4J: See http://www.slf4j.org/codes.html#version_mismatch for further details.
Exception in thread "main" java.lang.NoSuchMethodError: org.slf4j.helpers.MessageFormatter.arrayFormat(Ljava/lang/String;[Ljava/lang/Object;)Lorg/slf4j/helpers/FormattingTuple;
at ch.qos.logback.classic.spi.LoggingEvent.(LoggingEvent.java:114)
at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:468)
at ch.qos.logback.classic.Logger.filterAndLog_0_Or3Plus(Logger.java:424)
at ch.qos.logback.classic.Logger.info(Logger.java:628)
at com.test.RemoteTest.main(RemoteTest.java:11)
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder
by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
</encoder>
</appender>
<appender name="SYSLOG" class="ch.qos.logback.classic.net.SyslogAppender">
<syslogHost>myhost</syslogHost>
<facility>USER</facility>
<suffixPattern>[%thread] %logger %msg</suffixPattern>
</appender>
<root level="debug">
<appender-ref ref="SYSLOG"/>
<appender-ref ref="STDOUT"/>
</root>
</configuration>
- syslogHost - syslog server host to log to
- facility - identify the source of the message
- suffixPattern - format of the log message
The Java class to test the appenders:
package com.test;The rsyslogd host should have the following entry once you run the RemoteTest class:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class RemoteTest {
static final Logger logger = LoggerFactory.getLogger(RemoteTest.class);
public static void main(String[] args) {
logger.info("hello world");
}
}
Dec 12 16:16:37 my-noteb [main] com.test.RemoteTest hello world
3 comments:
Thanks. This is exactly what I was looking for.
Hi,
Where should I put logback.xml to be picked.
My application java file is at package
org/syslog/TestSysLog.java
I have put it under same package org/syslog
Is that fine ??
Please let me know
Great work guys...
Refresh Livingroom
Elegant Home Decor
Apartment Remodeling Trends
Post a Comment