Hi,
I am trying out the API side of log4j2 with the SLF4J adaptor. With the
sample code written i couldn't see the logging being done properly. Perhaps
i am doing something wrong here.
Firstly versions of the software are :-
1. JDK 1.8.x
2. Log4j2 (2.0.1)
3. SLF4J 1.7.7
4. SLF4J's Simple Logger (1.7.7)
Code written is as under
HelloWorld.java
--------------
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class HelloWorld {
private static final Logger logger = LogManager.getLogger("HelloWorld");
public static void main(String[] args) {
logger.error("Hello, World!");
logger.error("Logging in user {} with birthday {}", "Ted",
"1/10/1900");
}
}
Log4j.xml (Not sure if this is needed or not)
-------------
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} -
%msg%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="INFO">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
The output generated is
-----------------------------
[main] ERROR HelloWorld - org.apache.logging.log4j.spi.AbstractLogger
[main] ERROR HelloWorld - org.apache.logging.log4j.spi.AbstractLogger
Jars in classpath
----------------------
log4j-api-2.0.1.jar
log4j-to-slf4j-2.0.1.jar
slf4j-api-1.7.7
slf4j-simple-1.7.7
Also the code works fine if i remove the slf4j related jars and replace it
with log4j core.
Is there any configuration that i have missed ?
Thank You!
Regards,
-Yogesh