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.

Reply via email to