Skip to content
Advertisement

Type mismatch: cannot convert from org.slf4j.Logger to org.apache.log4j.Logger

i configure my environment in eclipse Mars but i got an error with the log4j. I use spring 4 and maven as dependency manager. Hier some part of code:

Eclipse show me an error on this line, the second part after the equals:

private static final Logger LOGGER = LoggerFactory.getLogger(PropertyConfiguration.class);

The error:

Type mismatch: cannot convert from org.slf4j.Logger to org.apache.log4j.Logger

My propertyConfiguration is into the com.myapp.bootstrap and the xml file into src/main/resources.

my log4j.xml file:

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

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

    <appender name="defaultAppender" class="org.apache.log4j.ConsoleAppender">
        <param name="encoding" value="UTF-8" />
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{ISO8601} %-5p [%t] %c{2}: %m%n" />
        </layout>
    </appender>

    <logger name="com.myapp" additivity="false">
        <level value="DEBUG" />
        <appender-ref ref="defaultAppender" />
    </logger>

    <root>
        <priority value="INFO" />
        <appender-ref ref="defaultAppender" />
    </root>

</log4j:configuration>

And someone any ideas?

Thank

Advertisement

Answer

Check your imports. Sometimes Eclipse chooses the import org.slf4j.Logger instead of org.apache.log4j.Logger.

Use combination of either

import java.util.logging.Level;
import java.util.logging.Logger;

or

import org.apache.log4j.Logger;
import org.apache.log4j.Priority;

or

Slf4j according to your library

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement