Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-1465

Default layouts for various appenders could be more consistent

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Won't Fix
    • Affects Version/s: 2.6.2
    • Fix Version/s: 2.7
    • Component/s: Appenders
    • Labels:
      None

      Description

      The appenders with layout support have different layouts as default. This could be improved, made more consistent and better documented:

      According to documentation:

      • ConsoleAppender - pattern %m%n
      • FileAppender - no default
      • FlumeAppender - RFC5424Layout
      • JMSAppender - SerializedLayout
      • KafkaAppender - formatted message
      • MemoryMappedFileAppender - no default
      • RandomAccessFileAppender - no default
      • RollingFileAppender - no default
      • RollingRandomAccessFileAppender - no default
      • SMTPAppender - SerializedLayout
      • SocketAppender - SerializedLayout
      • JeroMQAppender - If you do not specify a layout, the appender uses the default pattern appender returned by PatternLayout.createDefaultLayout()

      This is not accurate though, e.g. FileAppender (and its variants) have pattern %m%n as default.

      First we should update the documentation to match the implementation. But maybe we should also consider changing some of the defaults.

      I think that pattern %m%n make sense as default for Console and the various File appenders.

      I assume that RFC5424 make sense as default for Flume, but I don't know about Flume.

      I don't think that pattern %m%n make sense as default for JeroMQ. And it was probably a mistake (by me) to make formatted message as default for Kafka.

      And as highlighted by https://issues.apache.org/jira/browse/LOG4J2-1226 it's not good to have SerializedLayout as default for any appender.

      I suggest that the "generic binary" appenders JMSAppender, KafkaAppender, SocketAppender and JeroMQAppender have no default layout, make it mandatory to specify a layout for them. That will force the user to make a conscious choice of layout, which I think is good.

      SMTPAppender should probably have pattern %m%n as default just like Console and File.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                mikaelstaldal Mikael Ståldal
                Reporter:
                mikaelstaldal Mikael Ståldal
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: