logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kiran Badi <ad...@aayushs.com>
Subject Re: Logging complete exception trace.
Date Fri, 18 Sep 2015 18:05:13 GMT
Thanks Remko for reply, I think that's how I do it.

 Please see below the way I use it. I am on log4j2 and I have log4j-api,
log4j-core and log4j-web jars in the lib directory of my web app.

I import these 2 packages
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;


Create a static instance

 static final Logger log = LogManager.getLogger(myclass.class.getName());

then do use it in class file

                  catch (Exception ex) {
                         log.error("Got the exception", ex);
                    }

I was under impression that this should log the complete trace, but its not.

Any ideas as what I am missing ?




On Fri, Sep 18, 2015 at 1:49 PM, Remko Popma <remko.popma@gmail.com> wrote:

> In your application,
> do not use logger.error(exception);
> but use logger.error("some message", exception); instead.
>
> The first form will take the exception object as an object and calls
> toString() on it, which is not what you want.
>
> Remko
>
> Sent from my iPhone
>
> > On 2015/09/18, at 18:00, Kiran Badi <admin@aayushs.com> wrote:
> >
> > Hi All,
> >
> > I have below log42 xml in classes folder and I am on log4j2 . This
> setting
> > does not log exception and it just logs1 line exception.
> >
> > How do I make log4j2 to log complete exception trace in mysite log ?
> >
> >
> >
> > <?xml version="1.0" encoding="UTF-8"?>
> > <!--
> > To change this template, choose Tools | Templates
> > and open the template in the editor.
> > -->
> > <configuration>
> >    <Properties>
> >         <Property name="log-path">C:/logs/</Property>
> > <!--       <Property name="log-path">/home/mydrive/logs/</Property>-->
> >    </Properties>
> >    <Appenders>
> >        <RollingFile name="RollingFile" fileName="${log-path}/mysite.log"
> >
> > filePattern="${log-path}/indianads-%d{yyyy-MM-dd}-%i.log">
> >            <PatternLayout>
> >                <pattern>%d{dd/MMM/yyyy HH:mm:ss,SSS}- %c{1}:
> > %m%ex%n</pattern>
> >            </PatternLayout>
> >            <Policies>
> >                <SizeBasedTriggeringPolicy size="1 MB"/>
> >            </Policies>
> >            <DefaultRolloverStrategy max="24"/>
> >        </RollingFile>
> >    </Appenders>
> >    <Loggers>
> >        <Logger name="root" level="debug" additivity="false">
> >            <appender-ref ref="RollingFile" level="All"/>
> >        </Logger>
> >        <Root level="All" additivity="false">
> >            <AppenderRef ref="RollingFile"/>
> >        </Root>
> >    </Loggers>
> > </configuration>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>

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