https://issues.apache.org/bugzilla/show_bug.cgi?id=44765
Summary: SyslogAppender should not attempt to remove inital tabs
from stack trace lines
Product: Log4j
Version: 1.2
Platform: All
OS/Version: Linux
Status: NEW
Severity: normal
Priority: P2
Component: Appender
AssignedTo: [email protected]
ReportedBy: [EMAIL PROTECTED]
Prior to Log4J 1.2.15, the SyslogAppender removed the first character from each
stacktrace line, causing unwanted benavior (possibly exceptions).
This was partially fixed (ref issue 40502)
https://issues.apache.org/bugzilla/show_bug.cgi?id=40502
The above fix means that the first character of each stack trace line is
removed only, if it is a tab character ('\t').
I will argue, that the initial tab character should NOT be removed at all,
since it provides useful indentation, making it easier to view stacktraces in a
syslog. If, for some reason, it is not desirable to have tab characters in the
syslog, the tab character should be replaced with a suitable number of spaces.
EXAMPLE:
========
This stack-trace...
---------------------------------------------------------------------------
2008-04-07 12:23:03,479 ERROR com.acme.SyslogTest - Error with stacktrace
java.lang.RuntimeException: Second
at dk.cph.SyslogTest.testStackTrace(SyslogTest.java:61)
(...)
at
com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:40)
Caused by: java.lang.RuntimeException: First
... 17 more
---------------------------------------------------------------------------
...would, prior to 1.2.14, be displayed in syslog as...
---------------------------------------------------------------------------
Apr 7 12:14:04 localhost 2008-04-07 12:14:03,975 ERROR com.acme.SyslogTest -
Error with stacktrace
Apr 7 12:14:04 localhost java.lang.RuntimeException: Second
Apr 7 12:14:04 localhost at
dk.cph.SyslogTest.testStackTrace(SyslogTest.java:56)
(...)
Apr 7 12:14:04 localhost at
com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
Apr 7 12:14:04 localhost aused by: java.lang.RuntimeException: First
Apr 7 12:14:04 localhost ... 22 more
Apr 7 12:40:06 localhost 2008-04-07 12:23:03,479 ERROR com.acme.SyslogTest -
Error with stacktrace
---------------------------------------------------------------------------
(Notice the "aused by:" line, and the missing indentation).
With the proposed solution (below), the stack-trace would be displayed as:
---------------------------------------------------------------------------
Apr 7 12:14:04 localhost 2008-04-07 12:14:03,975 ERROR com.acme.SyslogTest -
Error with stacktrace
Apr 7 12:14:04 localhost java.lang.RuntimeException: Second
Apr 7 12:14:04 localhost at
dk.cph.SyslogTest.testStackTrace(SyslogTest.java:56)
(...)
Apr 7 12:14:04 localhost at
com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
Apr 7 12:14:04 localhost Caused by: java.lang.RuntimeException: First
Apr 7 12:14:04 localhost ... 22 more
Apr 7 12:40:06 localhost 2008-04-07 12:23:03,479 ERROR com.acme.SyslogTest -
Error with stacktrace
---------------------------------------------------------------------------
(note: with a long stacktrace, the indentation is clearly more useful)
PROPOSAL
========
While the above fix reinstates the "Caused by", I feel that reinserting the
initial tab (or spaces) would be preferable, since it would make it easier to
identify the "Caused by" statement in the stack-trace.
My proposal is to replace initial tab with 4 spaces, which could be achieved
with the following change to org.apache.log4j.net.SyslogAppender.java:
change:
if (s[i].charAt(0) == '\t') {
sqw.write(TAB+s[i].substring(1));
} else {
to:
if (s[i].charAt(0) == '\t') {
sqw.write(TAB+" "+s[i].substring(1));
} else {
(String garbage collection optimization could be achieved by replacing the
string concatenation with multiple calls to write, and/or introducing a
TAB_INDENT string constant).
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]