logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary Gregory <garydgreg...@gmail.com>
Subject Re: How to print timestamp on each log line of a stack trace?
Date Thu, 18 Dec 2014 15:12:47 GMT
Alexey,

At this point, since this is not trivial, I found create a Jira for a
feature request. It seems that what you want is to evaluate the separator
as a pattern expression. Right now, it is a string literal. Actually, you
might be able to get ONE evaluation when the configuration file is parsed
but maybe not, and that is not what you want anyway.

Gary

On Thu, Dec 18, 2014 at 10:04 AM, Alexey Zavizionov <
alexey.zavizionov@gmail.com> wrote:
>
> Any news on it?
>
> On Thu, Nov 6, 2014 at 3:03 PM, Alexey Zavizionov <
> alexey.zavizionov@gmail.com> wrote:
> >
> > Btw, I found "separator" option, but \n or %n didn't work for it!
> >
> >             <PatternLayout>
> >                 <pattern>%d{HH:mm:ss.SSS} : %m [] %xEx{separator(\n)}
> > %n</pattern>
> >             </PatternLayout>
> >
> > I want to use %d in it.
> >
> > Please try to fix the with it.
> >
> org.apache.logging.log4j.core.pattern.ThrowablePatternConverter.formatOption(Throwable,
> > StringBuilder)
> >
> >
> > On Thu, Nov 6, 2014 at 10:31 AM, Alexey Zavizionov <
> > alexey.zavizionov@gmail.com> wrote:
> >
> >> 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
> >>>
> >>>
> >
>


-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

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