Log4j 2
  1. Log4j 2
  2. LOG4J2-136

Syslog: Optional escaping of newlines in message body, optionally include stack trace

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.0-beta3
    • Fix Version/s: 2.0-beta4
    • Component/s: Appenders, Layouts
    • Labels:
    • Environment:

      N/A

      Description

      Syslog (both RFC-3164 and 5424) use newline characters to frame messages. As Log4J2 messages may include newlines in the message body, it is necessary to replace newlines with a configurable escape string.

      I've implemented a configuration option "newLineEscape" which accepts a replacement string. The default is to not escape newlines (i.e. current behavior).

      I've also implemented a configuration option "exceptionConverstion", which accepts the same options as PatternLayout's %exception field. If no value is specified, exceptions are not included.

        Activity

        Hide
        Scott Severtson added a comment -

        Looks good, and seems to work in my tests. A couple minor nits:

        1. The constant DEFAULT_CONVERSION_PATTERN is defined, but never used.
        2. On line 484 of RFC5424Layout.java on trunk, we attempt to use the charset in a logged error message, but it will only ever be null.
        3. Neither of the new parameters ended up with JavaDoc entries in either SyslogAppender or RFC5424Layout.

        Thanks!

        Show
        Scott Severtson added a comment - Looks good, and seems to work in my tests. A couple minor nits: 1. The constant DEFAULT_CONVERSION_PATTERN is defined, but never used. 2. On line 484 of RFC5424Layout.java on trunk, we attempt to use the charset in a logged error message, but it will only ever be null. 3. Neither of the new parameters ended up with JavaDoc entries in either SyslogAppender or RFC5424Layout. Thanks!
        Hide
        Ralph Goers added a comment -

        I applied your patch with a modification in revision 1426803. The change I made was to allow a Throwable converter pattern to be specified. If one is there it will be used to format the Throwable. Thanks for the patch.

        Please verifiy and close.

        Show
        Ralph Goers added a comment - I applied your patch with a modification in revision 1426803. The change I made was to allow a Throwable converter pattern to be specified. If one is there it will be used to format the Throwable. Thanks for the patch. Please verifiy and close.
        Hide
        Scott Severtson added a comment -

        Updated version of the patch, to incorporate a related feature:

        Adds an optional, non-defaulted ability to include stack traces in the syslog message. Only implemented for RFC-5424 (due to increased allowable message size), and only recommended over TCP transports (UDP limited to 4k by most OSes).

        Show
        Scott Severtson added a comment - Updated version of the patch, to incorporate a related feature: Adds an optional, non-defaulted ability to include stack traces in the syslog message. Only implemented for RFC-5424 (due to increased allowable message size), and only recommended over TCP transports (UDP limited to 4k by most OSes).
        Hide
        Scott Severtson added a comment -

        BTW, if you work with rsyslog, the logical newline escape string is "\012", which is compatible with how rsyslog escapes other control characters.

        Show
        Scott Severtson added a comment - BTW, if you work with rsyslog, the logical newline escape string is "\012", which is compatible with how rsyslog escapes other control characters.
        Hide
        Scott Severtson added a comment -

        Patch against trunk to support escaping newlines in syslog messages.

        Show
        Scott Severtson added a comment - Patch against trunk to support escaping newlines in syslog messages.

          People

          • Assignee:
            Ralph Goers
            Reporter:
            Scott Severtson
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development