[slf4j-dev] [JIRA] (SLF4J-422) Have slf4j-log4j12 include extra arguments to Logger methods

QOS.CH (JIRA) noreply-jira at qos.ch
Fri Dec 1 15:33:00 CET 2017


    [ https://jira.qos.ch/browse/SLF4J-422?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18982#comment-18982 ] 

Eric Pabst commented on SLF4J-422:
----------------------------------

I'm going to start preparing a pull request.

> Have slf4j-log4j12 include extra arguments to Logger methods
> ------------------------------------------------------------
>
>                 Key: SLF4J-422
>                 URL: https://jira.qos.ch/browse/SLF4J-422
>             Project: SLF4J
>          Issue Type: Improvement
>          Components: Implementations
>    Affects Versions: 1.7.22
>         Environment: All
>            Reporter: Eric Pabst
>            Assignee: SLF4J developers list
>
> 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 log4j or 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 slf4j-log4j12, 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://... 



--
This message was sent by Atlassian JIRA
(v7.3.1#73012)


More information about the slf4j-dev mailing list