logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexey Zavizionov <alexey.zavizio...@gmail.com>
Subject Re: How to print timestamp on each log line of a stack trace?
Date Thu, 06 Nov 2014 08:31:24 GMT
Thank! Where to put it in my conf to not broke other log configuration?
05 нояб. 2014 г. 21:42 пользователь "Ralph Goers" <
ralph.goers@dslextreme.com> написал:

> You would have to create a custom ThrowablePatternConverter.
>
> Ralph
>
> > On Nov 5, 2014, at 12:03 PM, Alexey Zavizionov <
> alexey.zavizionov@gmail.com> wrote:
> >
> > Here is the output, when an application is throwing an exception, logging
> > it to log, including its stack trace.
> >
> > E 1105-2042:17,349 c.e.TestLog error-message [main]
> > java.lang.Exception: SomeError
> >  at com.examples.TestLog.main(TestLog.java:15)
> >
> > Want to see the timestamp "E 1105-2042:17,349" on each log line.
> > How can I do? Is it possible with configuration file?
> >
> > TestLog.java
> > =============================================
> > public class TestLog {
> > private static final Logger LOGGER =
> LoggerFactory.getLogger(TestLog.class);
> > public static void main(String[] args) {
> > LOGGER.error("error-", new Exception("SomeError"));
> > }
> > }
> > =============================================
> >
> > log4j2.xml
> > =============================================
> > <?xml version="1.0" encoding="UTF-8"?>
> > <Configuration status="WARN">
> >    <Appenders>
> >        <RollingRandomAccessFile name="server" fileName="server.log"
> > filePattern="server-%d-%i.log.zip" immediateFlush="false">
> >            <ThresholdFilter level="DEBUG" />
> >            <PatternLayout>
> >                <pattern>%level{length=1} %date{MMdd-HHmm:ss,SSS}
> > %logger{1.} %message [%thread]%n</pattern>
> >            </PatternLayout>
> >            <Policies>
> >                <TimeBasedTriggeringPolicy />
> >                <SizeBasedTriggeringPolicy size="50 MB" />
> >            </Policies>
> >            <DefaultRolloverStrategy max="100" />
> >        </RollingRandomAccessFile>
> >    </Appenders>
> >    <Loggers>
> >        <Root level="DEBUG">
> >            <AppenderRef ref="server" />
> >        </Root>
> >    </Loggers>
> > </Configuration>
> > =============================================
> >
> > I have log:
> > ==============================================
> > E 1105-2042:17,349 c.e.TestLog error-message [main]
> > java.lang.Exception: SomeError
> >  at com.examples.TestLog.main(TestLog.java:15)
> > ==============================================
> >
> > Hope to see log:
> > ==============================================
> > E 1105-2042:17,349 c.e.TestLog error-message  [main]
> > E 1105-2042:17,349 java.lang.Exception: SomeError
> > E 1105-2042:17,349  at com.examples.TestLog.main(TestLog.java:15)
> > ==============================================
> >
> > Regards,
> > Alexey.
>
>
> ---------------------------------------------------------------------
> 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