[ 
https://issues.apache.org/jira/browse/SOLR-15630?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Chris M. Hostetter updated SOLR-15630:
--------------------------------------
    Attachment: SOLR-15630.patch
        Status: Open  (was: Open)

The attached patch moves the prefixes into the log4j {{PatternLayout}} using 
{{%notEmpty}} .

The resulting log files hsould be consistent with previous versions, except 
that I made a conscious choice to move all the existing whitespace separators 
between the MDC values inside the {{%notEmpty}} macros, so that the log 
messages would be more compact when any of the MDC values aren't set - but 
these can be moved out if people miss the {{[    ]}} blocks from threads that 
aren't collection/core specific.
----
the java changes were made by hand, the config file changes were made via...
{code}
find -name log4j\*xml | xargs perl ~/tmp/fix-mdc.pl
{code}
{code}
#!/usr/bin/perl -pi
BEGIN {
    %prefix = qw( node_name n
                  collection c
                  shard s
                  replica r
                  core x
                  trace_id t );
}
s<(\s*)\%X\{(.*?)\}><%notEmpty{$1$prefix{$2}:%X{$2}}>g;
{code}

> MDC "prefix labels" should be handled by Layout - not hardcoded in solr code
> ----------------------------------------------------------------------------
>
>                 Key: SOLR-15630
>                 URL: https://issues.apache.org/jira/browse/SOLR-15630
>             Project: Solr
>          Issue Type: Improvement
>      Security Level: Public(Default Security Level. Issues are Public) 
>            Reporter: Chris M. Hostetter
>            Assignee: Chris M. Hostetter
>            Priority: Major
>         Attachments: SOLR-15630.patch
>
>
> Currently, when Solr puts values in the MDC for logging, it always prepends 
> them with a "CHAR" + "COLON" prefix that uniquely identifies what the value 
> is – even though the MDC is a map and every value has a "key" associated with 
> it that identifies what it is, ex...
> {code:java}
>   public static void setCollection(String collection) {
>     if (collection != null) {
>       MDC.put(COLLECTION_PROP, "c:" + collection);
>     } else {
>       MDC.remove(COLLECTION_PROP);
>     }
>   }
> {code}
> This choice evidently traces back to when MDC values where initially added 
> SOLR-6673/SOLR-7590 (when Solr was still using slf4j->JUL IIUC) because that 
> was best (only?) way folks found to ensure that log messages that did _not_ 
> have values for specific MDC keys weren't cluttered with valueless prefixes  
> even when a log message didn't correspond to a specific collection (or 
> replica, or shard, etc...)
> But with modern log4j, we can use use things like the {{%notEmpty}} syntax to 
> prevent excessive verbosity when MDC values aren't set – allowing us to move 
> the prefixes out of the Solr code and into Solr default log4j configuration – 
> so that users who customize their log4j configuration with things like 
> {{%mdc}} (or JSON logging) can get the "bare" values w/o hardcoded prefixes. 
> (while keeping the exact same default log format ... or even improving it by 
> removing some of the wasted whitespace)
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org
For additional commands, e-mail: issues-h...@solr.apache.org

Reply via email to