logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matt Sicker <boa...@gmail.com>
Subject Re: Log4j2 with SL4J Adapter
Date Fri, 22 Aug 2014 18:23:37 GMT
Using log4j-to-slf4j is for when you want to use log4j-api but with an
slf4j implementation (like logback). log4j-slf4j-impl would allow you to
use slf4j-api and have that log to log4j-core.


On 22 August 2014 08:27, Yogesh Rao <yogu13@gmail.com> wrote:

> 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
>



-- 
Matt Sicker <boards@gmail.com>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message