You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by "Anders Kreinøe (JIRA)" <ji...@apache.org> on 2015/06/15 12:57:00 UTC
[jira] [Created] (LOG4J2-1054) PatternLayout in Socket appender
writes the stacktrace of an exception to the socket, after it has written
the pattern.
Anders Kreinøe created LOG4J2-1054:
--------------------------------------
Summary: PatternLayout in Socket appender writes the stacktrace of an exception to the socket, after it has written the pattern.
Key: LOG4J2-1054
URL: https://issues.apache.org/jira/browse/LOG4J2-1054
Project: Log4j 2
Issue Type: Bug
Components: Appenders
Affects Versions: 2.3
Reporter: Anders Kreinøe
I have the following configuration:
{code:xml}
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" monitorInterval="30">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout>
<Pattern>%d %p [%X{userName} - %X{userId} - %X{requestId} - %X{requestName} - %c{2.}] %m%n</Pattern>
</PatternLayout>
</Console>
<Socket name="logstash" host="localhost" protocol="tcp" port="5000" ignoreExceptions="false" connectTimeoutMillis="5000" reconnectionDelayMillis="1000">
<PatternLayout>
<Pattern>{"@timestamp":"%d{yyyy-MM-dd'T'HH:mm:ss.SSSZZ}","logger":"%c{1.}","level":"%p","message":"%enc{%m}","exception":"%enc{%ex}","logger_full_name":"%c","mdc_map":"%mdc","uuid":"%u{ramdom}","thread":"%t","application":"logstash-log4j-test","type":"java","sub_type":"log4j"}%n</Pattern>
</PatternLayout>
</Socket>
</Appenders>
<Loggers>
<Root level="TRACE">
<AppenderRef ref="Console"/>
<AppenderRef ref="logstash"/>
</Root>
</Loggers>
</Configuration>
{code}
when i run the following code:
{code:java}
package dk.cirque.tmp.logstashLog4jTest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class JavaMain {
public static void main(String[] args) {
final Logger log = LoggerFactory.getLogger(JavaMain.class);
log.info("Info log from log4j, 1 - med exception", new RuntimeException("Message of runtime exception for loggin."));
log.info("Info log from log4j, 2 with newline" + System.lineSeparator() + "this is on a new line.");
}
}
{code}
i get the following writting to the console:
{noformat}
~/ nc -l 5000
{"@timestamp":"2015-06-15T12:50:04.370+0200","logger":"d.c.t.l.JavaMain","level":"INFO","message":"Info log from log4j, 1 - med exception","exception":"java.lang.RuntimeException: Message of runtime exception for loggin.\n at dk.cirque.tmp.logstashLog4jTest.JavaMain.main(JavaMain.java:13)\n at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)\n at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n at java.lang.reflect.Method.invoke(Method.java:606)\n at sbt.Run.invokeMain(Run.scala:67)\n at sbt.Run.run0(Run.scala:61)\n at sbt.Run.sbt$Run$$execute$1(Run.scala:51)\n at sbt.Run$$anonfun$run$1.apply$mcV$sp(Run.scala:55)\n at sbt.Run$$anonfun$run$1.apply(Run.scala:55)\n at sbt.Run$$anonfun$run$1.apply(Run.scala:55)\n at sbt.Logger$$anon$4.apply(Logger.scala:85)\n at sbt.TrapExit$App.run(TrapExit.scala:248)\n at java.lang.Thread.run(Thread.java:745)\n","logger_full_name":"dk.cirque.tmp.logstashLog4jTest.JavaMain","mdc_map":"{}","uuid":"47907581-134c-11e5-b741-5c514f566c15","thread":"run-main-4a","application":"logstash-log4j-test","type":"java","sub_type":"log4j"}
java.lang.RuntimeException: Message of runtime exception for loggin.
at dk.cirque.tmp.logstashLog4jTest.JavaMain.main(JavaMain.java:13) [classes/:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_55]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_55]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_55]
at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_55]
at sbt.Run.invokeMain(Run.scala:67) [run-0.13.8.jar:0.13.8]
at sbt.Run.run0(Run.scala:61) [run-0.13.8.jar:0.13.8]
at sbt.Run.sbt$Run$$execute$1(Run.scala:51) [run-0.13.8.jar:0.13.8]
at sbt.Run$$anonfun$run$1.apply$mcV$sp(Run.scala:55) [run-0.13.8.jar:0.13.8]
at sbt.Run$$anonfun$run$1.apply(Run.scala:55) [run-0.13.8.jar:0.13.8]
at sbt.Run$$anonfun$run$1.apply(Run.scala:55) [run-0.13.8.jar:0.13.8]
at sbt.Logger$$anon$4.apply(Logger.scala:85) [logging-0.13.8.jar:0.13.8]
at sbt.TrapExit$App.run(TrapExit.scala:248) [run-0.13.8.jar:0.13.8]
at java.lang.Thread.run(Thread.java:745) [?:1.7.0_55]
{"@timestamp":"2015-06-15T12:50:04.376+0200","logger":"d.c.t.l.JavaMain","level":"INFO","message":"Info log from log4j, 2 with newline\nthis is on a new line.","exception":"","logger_full_name":"dk.cirque.tmp.logstashLog4jTest.JavaMain","mdc_map":"{}","uuid":"47907582-134c-11e5-b741-5c514f566c15","thread":"run-main-4a","application":"logstash-log4j-test","type":"java","sub_type":"log4j"}
{noformat}
It har written the following (where only number 1 and 3 was expected):
# The result of the pattern for the first exception
# The output of printStacktrace() for the cause exception of the first log statesment.
# The result of the pattern for the second exception.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org