Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Config SLF4J using library to use LOG4J configuration

I have a project using log4j. Now I have to introduce a library using slf4j. Can I ask slf4j to initialize itself based on log4j config? So I basicly want log4j as underlying library under slf4j.

UPDATE:

log4j config is like this:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration debug="true" xmlns:log4j="http://jakarta.apache.org/log4j/">
    <appender name="fileAppender" class="org.apache.log4j.rolling.RollingFileAppender">
        <param name="file" value="${log.dir}/${log.file}.log" />
        <param name="append" value="true" />
        <rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
            <param name="FileNamePattern" value="${archive.log.dir}/${log.file}.%d{yyyy-MM-dd}.gz" />
            <param name="ActiveFileName" value="${log.dir}/${log.file}.log"/>
        </rollingPolicy>
        <layout class="org.apache.log4j.EnhancedPatternLayout">
            <param name="ConversionPattern" value="%d{yyMMdd HH:mm:ss,SSS} [%t] %-5p %c %X %m%n" />
        </layout>
    </appender>
    <logger name="org.hibernate"> 
        <level value="ALL" /> 
        <appender-ref ref="fileAppender"/> 
    </logger> 
    <root>
        <priority value="info" />
        <appender-ref ref="fileAppender" />
    </root>
</log4j:configuration>

I also use apache-log4j-extras version 1.0. log4j version is 1.2.16

like image 792
Gábor Lipták Avatar asked Nov 29 '10 11:11

Gábor Lipták


1 Answers

Yes, you need three jar files in your project's classpath:

slf4j-api-1.6.1.jar       // the slf4j API
slf4j-log4j12-1.6.1.jar   // log4j bindings for slf4j
log4j-1.2.15.jar          // log4j itself

Make sure you have the same version of slf4j-api and slf4j-log4j12, otherwise it won't work. You can also use the newest log4j version, 1.2.16 if I'm not mistaken.

like image 100
darioo Avatar answered Oct 20 '22 17:10

darioo