Uploaded image for project: 'logback'
  1. logback
  2. LOGBACK-1356

Have ILoggingEvent implementations include extra arguments to Logger methods

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 1.2.3
    • Fix Version/s: None
    • Component/s: logback-classic
    • Labels:
      None
    • Environment:

      slf4j 1.7.22

      MacOS, Java 8

      Description

      The purpose of logging to slf4j is to allow code to log information without worrying about which implementation and format will be used for actual logging.  In deployed environments, we prefer JSON logging using logstash to be consumed by Splunk, which handles JSON very nicely.  However, for local development and testing, we prefer text output via logback-classic.

      We often want to log extra fields to show up in the JSON output such as 

      {{{ "timestamp": "2017...", "message": "Event X happened", "userName": "bob", "url": "http://..."}}}

      To accomplish this, we use logstash's StructuredArgument to provide extra arguments to the Logger:

      import static net.logstash.logback.argument.StructuredArguments.keyValue;
      ...
        LOGGER.info("Event X happened", keyValue("userName", "bob"), keyValue("url", "http://..."));

      We don't want to include {}'s in the message or else it would log the username and url both in the message and as separate JSON properties.

      However, when binding to logback-classic, it is logged without these extra arguments:

      INFO 2017... Event X happened

      It would help immensely to include these extra arguments automatically if present:

      INFO 2017... Event X happened username=bob url=http://... 

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                logback-dev Logback dev list
                Reporter:
                epabst Eric Pabst
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated: