configure SLF4J with log4j

2

I have a somewhat confusing problem but I will try to explain, I am working on a project that is using some external libraries, and I would like to implement a log, I have already seen that in the external packages they use the SLF4J package. So I did a project to test component settings to write to a file and it was all going fine until I tried for SLF4J in the project I'm working on, because when I set up log4j in the project it apparently activated all the calls from the external libraries and started to show everything in the console, being that it did not record anything in the log file, apparently it ignores the configuration file, but at the same time this is not true because when the shot everything stops.

The project is a console and does not use mavem because of network configuration problems here at work. What I want is for him to write the log to the file and preferably without the information from the external libraries, but if it is not possible, everything can log everything. Below is the log4j.xml file with the sensitive information changed.

>
    <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
  <appender name="console" class="org.apache.log4j.ConsoleAppender"> 
    <param name="Target" value="System.out"/> 
    <param name="threshold" value="DEBUG" />
    <layout class="org.apache.log4j.PatternLayout"> 
      <param name="ConversionPattern" value="%-5p %c{1} - %m%n"/> 
    </layout> 
  </appender> 
  <appender name="file" class="org.apache.log4j.FileAppender"> 
     <param name="file" value="d:/temp/app.log" />
     <param name="append" value="true" />
     <param name="threshold" value="WARN" />
     <layout class="org.apache.log4j.PatternLayout">
          <param name="ConversionPattern" value="%d{ISO8601} %-5p [%c{1}] - %m%n" />
     </layout>
  </appender> 
   <root> 
    <priority value ="debug" /> 
    <appender-ref ref="console" /> 
    <appender-ref ref="file" /> 
  </root>
</log4j:configuration>
    
asked by anonymous 13.07.2015 / 16:02

1 answer

2
Okay, after a lot of research I found the problem, basically one of the third-party packages I'm using, used SLF4J and distributed the JAR with slf4j-simple-1.7.12.jar, so when I set up the LOG4J in the application we are building, he would find the other example implementation first and ignore the rest. What I did was to open this package, take the other implementation and thus only the concrete implementation of LOG4J. From what I understand this failure can happen whenever you have more than one concrete log implementation being used with SLF4J.

    
15.07.2015 / 16:50