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 bu...@apache.org on 2008/04/07 13:24:28 UTC

DO NOT REPLY [Bug 44765] New: SyslogAppender should not attempt to remove inital tabs from stack trace lines

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: log4j-dev@logging.apache.org
        ReportedBy: morten.hattesen@gmail.com


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: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


DO NOT REPLY [Bug 44765] SyslogAppender should not attempt to remove inital tabs from stack trace lines

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=44765


Curt Arnold <ca...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Blocks|45527                       |




-- 
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: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


DO NOT REPLY [Bug 44765] SyslogAppender should not attempt to remove inital tabs from stack trace lines

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=44765


Thorbjørn Ravn Andersen <th...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Blocks|                            |45527




-- 
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: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


DO NOT REPLY [Bug 44765] SyslogAppender should not attempt to remove inital tabs from stack trace lines

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=44765


Curt Arnold <ca...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID




--- Comment #3 from Curt Arnold <ca...@apache.org>  2008-08-12 14:42:43 PST ---
Tab characters are prohibited in the MESSAGE section of the packet (see
http://www.ietf.org/rfc/rfc3164.txt?number=3164) along with all other
non-printable characters.

The code fragment that is suggested to be changed does not appear in the
current SVN HEAD (and as far back as the fix for bug 40502) as I can tell.  The
current code is:

      String[] s = event.getThrowableStrRep();
      if (s != null) {
        for(int i = 0; i < s.length; i++) {
            if (s[i].startsWith("\t")) {
               sqw.write(hdr+TAB+s[i].substring(1));
            } else {
               sqw.write(hdr+s[i]);
            }
        }
      }

This should replace any leading tab in the stack trace with the value of
SyslogAppender.TAB (which is initialized at four spaces).

The current code does not address cases where non-printable characters appear
in other positions, but it does appear to do the best possible when the stack
trace starts with a single tab character (which is a common in mainstream
JVM's).  As far as I can tell, the behavior described in the bug report should
not occur with the current SVN head, and I'm going to mark the bug as INVALID. 
If I've misunderstood, please reopen after testing with the SVN HEAD and
providing a patch against the current SVN HEAD.


-- 
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: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


DO NOT REPLY [Bug 44765] SyslogAppender should not attempt to remove inital tabs from stack trace lines

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=44765


Thorbjørn Ravn Andersen <th...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |thorbjoern@gmail.com




--- Comment #1 from Thorbjørn Ravn Andersen <th...@gmail.com>  2008-07-03 12:59:07 PST ---
Is there any reason why this behaviour should NOT be changed to include all
characters logged?  Does the first character have special meaning in syslog
messages?


-- 
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: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


DO NOT REPLY [Bug 44765] SyslogAppender should not attempt to remove inital tabs from stack trace lines

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=44765


Morten Hattesen <mo...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |morten.hattesen@gmail.com




--- Comment #2 from Morten Hattesen <mo...@gmail.com>  2008-07-03 13:38:51 PST ---
(In reply to comment #1)
> Is there any reason why this behaviour should NOT be changed to include all
> characters logged?  Does the first character have special meaning in syslog
> messages?

No, the first character has no special meaning.

But since stack-traces are indented using a leading TAB character, it is
generally a good idea to expand this to a number (4) of spaces to ensure
consistent rendering of the stack-trace. But the TAB character should
definitely NOT be truncated as part of the Syslog appender, as is the case
today.


-- 
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: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org