Apache Solr open-source search software
SOLR-15630: Logging MDC values no longer include a hardcoded prefix, allowing custom logging configurations access to the plain values.
Chris Hostetterb0a4b0213016
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 43e0b366777..12bfdde6f6e 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -145,6 +145,9 @@ when told to. The admin UI now tells it to. (Nazerke Seidan, David Smiley)* SOLR-10887: Migrate "managed-schema" file naming to "managed-schema.xml" file name, with a fallback to the legacy "managed-schema". (Eric Pugh, David Smiley)+* SOLR-15630: Logging MDC values no longer include a hardcoded prefix, allowing custom logging configurations access to the plain values.+ The default log4j2.xml PatternLayout has been updated to ensure the values are formatted with the existing prefixes. (hossman)+Build---------------------diff --git a/solr/benchmark/log4j2-bench.xml b/solr/benchmark/log4j2-bench.xmlindex ae4cecb5030..f0fd8766816 100644--- a/solr/benchmark/log4j2-bench.xml+++ b/solr/benchmark/log4j2-bench.xml@@ -23,7 +23,7 @@<Console name="STDOUT" target="SYSTEM_OUT"><PatternLayout><Pattern>- %maxLen{%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p (%t) [%X{collection} %X{shard} %X{replica} %X{core}] %c{1.}+ %maxLen{%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p (%t) [%notEmpty{c:%X{collection}}%notEmpty{ s:%X{shard}}%notEmpty{ r:%X{replica}}%notEmpty{ x:%X{core}}] %c{1.}%m%notEmpty{ =>%ex{short}}}{10240}%n</Pattern></PatternLayout>@@ -35,7 +35,7 @@filePattern="${sys:solr.log.dir:-work/solr-logs}/${sys:solr.log.name:-solr}.log.%i"><PatternLayout><Pattern>- %maxLen{%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p (%t) [%X{collection} %X{shard} %X{replica} %X{core}] %c{1.}+ %maxLen{%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p (%t) [%notEmpty{c:%X{collection}}%notEmpty{ s:%X{shard}}%notEmpty{ r:%X{replica}}%notEmpty{ x:%X{core}}] %c{1.}%m%notEmpty{ =>%ex{short}}}{10240}%n</Pattern></PatternLayout>@@ -52,7 +52,7 @@filePattern="${sys:solr.log.dir}/${sys:solr.log.name}_slow_requests.log.%i"><PatternLayout><Pattern>- %maxLen{%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p (%t) [%X{collection} %X{shard} %X{replica} %X{core}] %c{1.}+ %maxLen{%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p (%t) [%notEmpty{c:%X{collection}}%notEmpty{ s:%X{shard}}%notEmpty{ r:%X{replica}}%notEmpty{ x:%X{core}}] %c{1.}%m%notEmpty{ =>%ex{short}}}{10240}%n</Pattern></PatternLayout>@@ -69,7 +69,7 @@fileName="${sys:solr.log.dir:-build/work/solr-logs}/${sys:solr.log.name:-solr}_random_counts.log"><PatternLayout><Pattern>- %maxLen{%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p (%t) [%X{collection} %X{shard} %X{replica} %X{core}] %c{1.}+ %maxLen{%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p (%t) [%notEmpty{c:%X{collection}}%notEmpty{ s:%X{shard}}%notEmpty{ r:%X{replica}}%notEmpty{ x:%X{core}}] %c{1.}%m%notEmpty{ =>%ex{short}}}{10240}%n</Pattern></PatternLayout>diff --git a/solr/benchmark/src/test-files/log4j2.xml b/solr/benchmark/src/test-files/log4j2.xmlindex b77dd4a08ff..e54e11b474b 100644--- a/solr/benchmark/src/test-files/log4j2.xml+++ b/solr/benchmark/src/test-files/log4j2.xml@@ -23,7 +23,7 @@<Console name="STDOUT" target="SYSTEM_OUT"><PatternLayout><Pattern>- %maxLen{%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p (%t) [%X{collection} %X{shard} %X{replica} %X{core}] %c{1.}+ %maxLen{%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p (%t) [%notEmpty{c:%X{collection}}%notEmpty{ s:%X{shard}}%notEmpty{ r:%X{replica}}%notEmpty{ x:%X{core}}] %c{1.}%m%notEmpty{ =>%ex{short}}}{10240}%n</Pattern></PatternLayout>@@ -35,7 +35,7 @@filePattern="${sys:solr.log.dir:-build/work/solr-logs}/${sys:solr.log.name:-solr}.log.%i"><PatternLayout><Pattern>- %maxLen{%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p (%t) [%X{collection} %X{shard} %X{replica} %X{core}] %c{1.}+ %maxLen{%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p (%t) [%notEmpty{c:%X{collection}}%notEmpty{ s:%X{shard}}%notEmpty{ r:%X{replica}}%notEmpty{ x:%X{core}}] %c{1.}%m%notEmpty{ =>%ex{short}}}{10240}%n</Pattern></PatternLayout>@@ -52,7 +52,7 @@filePattern="${sys:solr.log.dir:-build/work/solr-logs}/${sys:solr.log.name:-solr}_slow_requests.log.%i"><PatternLayout><Pattern>- %maxLen{%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p (%t) [%X{collection} %X{shard} %X{replica} %X{core}] %c{1.}+ %maxLen{%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p (%t) [%notEmpty{c:%X{collection}}%notEmpty{ s:%X{shard}}%notEmpty{ r:%X{replica}}%notEmpty{ x:%X{core}}] %c{1.}%m%notEmpty{ =>%ex{short}}}{10240}%n</Pattern></PatternLayout>@@ -68,7 +68,7 @@fileName="${sys:solr.log.dir:-build/work/solr-logs}/${sys:solr.log.name:-solr}_random_counts.log"><PatternLayout><Pattern>- %maxLen{%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p (%t) [%X{collection} %X{shard} %X{replica} %X{core}] %c{1.}+ %maxLen{%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p (%t) [%notEmpty{c:%X{collection}}%notEmpty{ s:%X{shard}}%notEmpty{ r:%X{replica}}%notEmpty{ x:%X{core}}] %c{1.}%m%notEmpty{ =>%ex{short}}}{10240}%n</Pattern></PatternLayout>diff --git a/solr/contrib/clustering/src/test-files/log4j2.xml b/solr/contrib/clustering/src/test-files/log4j2.xmlindex ed01a6b2c76..5e696935965 100644--- a/solr/contrib/clustering/src/test-files/log4j2.xml+++ b/solr/contrib/clustering/src/test-files/log4j2.xml@@ -21,7 +21,7 @@<Console name="STDERR" target="SYSTEM_ERR"><PatternLayout><Pattern>- %maxLen{%-4r %-5p (%t) [%X{node_name} %X{collection} %X{shard} %X{replica} %X{core} %X{trace_id}] %c{1.} %m%notEmpty{+ %maxLen{%-4r %-5p (%t) [%notEmpty{n:%X{node_name}}%notEmpty{ c:%X{collection}}%notEmpty{ s:%X{shard}}%notEmpty{ r:%X{replica}}%notEmpty{ x:%X{core}}%notEmpty{ t:%X{trace_id}}] %c{1.} %m%notEmpty{=>%ex{short}}}{10240}%n</Pattern></PatternLayout>diff --git a/solr/contrib/gcs-repository/src/test-files/log4j2.xml b/solr/contrib/gcs-repository/src/test-files/log4j2.xmlindex 46ad20c18ee..6b02a3b06b4 100644--- a/solr/contrib/gcs-repository/src/test-files/log4j2.xml+++ b/solr/contrib/gcs-repository/src/test-files/log4j2.xml@@ -21,7 +21,7 @@<Console name="STDERR" target="SYSTEM_ERR"><PatternLayout><Pattern>- %maxLen{%-4r %-5p (%t) [%X{node_name} %X{collection} %X{shard} %X{replica} %X{core} %X{trace_id}] %c{1.} %m%notEmpty{+ %maxLen{%-4r %-5p (%t) [%notEmpty{n:%X{node_name}}%notEmpty{ c:%X{collection}}%notEmpty{ s:%X{shard}}%notEmpty{ r:%X{replica}}%notEmpty{ x:%X{core}}%notEmpty{ t:%X{trace_id}}] %c{1.} %m%notEmpty{=>%ex{short}}}{10240}%n</Pattern></PatternLayout>@@ -50,7 +50,7 @@<Console name="STDERR" target="SYSTEM_ERR"><PatternLayout><Pattern>- %-4r %-5p (%t) [%X{node_name} %X{collection} %X{shard} %X{replica} %X{core}] %c{1.} %m%n+ %-4r %-5p (%t) [%notEmpty{n:%X{node_name}}%notEmpty{ c:%X{collection}}%notEmpty{ s:%X{shard}}%notEmpty{ r:%X{replica}}%notEmpty{ x:%X{core}}] %c{1.} %m%n</Pattern></PatternLayout></Console>diff --git a/solr/contrib/s3-repository/src/test-files/log4j2.xml b/solr/contrib/s3-repository/src/test-files/log4j2.xmlindex 229a9316418..950caea970d 100644--- a/solr/contrib/s3-repository/src/test-files/log4j2.xml+++ b/solr/contrib/s3-repository/src/test-files/log4j2.xml@@ -21,7 +21,7 @@<Console name="STDERR" target="SYSTEM_ERR"><PatternLayout><Pattern>- %maxLen{%-4r %-5p (%t) [%X{node_name} %X{collection} %X{shard} %X{replica} %X{core} %X{trace_id}] %c{1.} %m%notEmpty{+ %maxLen{%-4r %-5p (%t) [%notEmpty{n:%X{node_name}}%notEmpty{ c:%X{collection}}%notEmpty{ s:%X{shard}}%notEmpty{ r:%X{replica}}%notEmpty{ x:%X{core}}%notEmpty{ t:%X{trace_id}}] %c{1.} %m%notEmpty{=>%ex{short}}}{10240}%n</Pattern></PatternLayout>@@ -50,7 +50,7 @@<Console name="STDERR" target="SYSTEM_ERR"><PatternLayout><Pattern>- %-4r %-5p (%t) [%X{node_name} %X{collection} %X{shard} %X{replica} %X{core}] %c{1.} %m%n+ %-4r %-5p (%t) [%notEmpty{n:%X{node_name}}%notEmpty{ c:%X{collection}}%notEmpty{ s:%X{shard}}%notEmpty{ r:%X{replica}}%notEmpty{ x:%X{core}}] %c{1.} %m%n</Pattern></PatternLayout></Console>diff --git a/solr/core/src/java/org/apache/solr/logging/MDCLoggingContext.java b/solr/core/src/java/org/apache/solr/logging/MDCLoggingContext.javaindex 492735be6e7..613f351d631 100644--- a/solr/core/src/java/org/apache/solr/logging/MDCLoggingContext.java+++ b/solr/core/src/java/org/apache/solr/logging/MDCLoggingContext.java@@ -42,7 +42,7 @@ public class MDCLoggingContext {public static void setCollection(String collection) {if (collection != null) {- MDC.put(COLLECTION_PROP, "c:" + collection);+ MDC.put(COLLECTION_PROP, collection);} else {MDC.remove(COLLECTION_PROP);}@@ -50,7 +50,7 @@ public class MDCLoggingContext {public static void setTracerId(String traceId) {if (!StringUtils.isEmpty(traceId)) {- MDC.put(TRACE_ID, "t:" + traceId);+ MDC.put(TRACE_ID, traceId);} else {MDC.remove(TRACE_ID);}@@ -58,7 +58,7 @@ public class MDCLoggingContext {public static void setShard(String shard) {if (shard != null) {- MDC.put(SHARD_ID_PROP, "s:" + shard);+ MDC.put(SHARD_ID_PROP, shard);} else {MDC.remove(SHARD_ID_PROP);}@@ -66,7 +66,7 @@ public class MDCLoggingContext {public static void setReplica(String replica) {if (replica != null) {- MDC.put(REPLICA_PROP, "r:" + replica);+ MDC.put(REPLICA_PROP, replica);} else {MDC.remove(REPLICA_PROP);}@@ -74,7 +74,7 @@ public class MDCLoggingContext {public static void setCoreName(String core) {if (core != null) {- MDC.put(CORE_NAME_PROP, "x:" + core);+ MDC.put(CORE_NAME_PROP, core);} else {MDC.remove(CORE_NAME_PROP);}@@ -100,7 +100,7 @@ public class MDCLoggingContext {private static void setNodeName(String node) {if (node != null) {- MDC.put(NODE_NAME_PROP, "n:" + node);+ MDC.put(NODE_NAME_PROP, node);} else {MDC.remove(NODE_NAME_PROP);}diff --git a/solr/core/src/test-files/log4j2.xml b/solr/core/src/test-files/log4j2.xmlindex 53dcae5c748..0e8f08c0c61 100644--- a/solr/core/src/test-files/log4j2.xml+++ b/solr/core/src/test-files/log4j2.xml@@ -21,7 +21,7 @@<Console name="STDERR" target="SYSTEM_ERR"><PatternLayout><Pattern>- %maxLen{%-4r %-5p (%t) [%X{node_name} %X{collection} %X{shard} %X{replica} %X{core} %X{trace_id}] %c{1.} %m%notEmpty{+ %maxLen{%-4r %-5p (%t) [%notEmpty{n:%X{node_name}}%notEmpty{ c:%X{collection}}%notEmpty{ s:%X{shard}}%notEmpty{ r:%X{replica}}%notEmpty{ x:%X{core}}%notEmpty{ t:%X{trace_id}}] %c{1.} %m%notEmpty{=>%ex{short}}}{10240}%n</Pattern></PatternLayout>diff --git a/solr/core/src/test/org/apache/solr/metrics/reporters/SolrSlf4jReporterTest.java b/solr/core/src/test/org/apache/solr/metrics/reporters/SolrSlf4jReporterTest.javaindex b78e45bb211..65b6a090d9d 100644--- a/solr/core/src/test/org/apache/solr/metrics/reporters/SolrSlf4jReporterTest.java+++ b/solr/core/src/test/org/apache/solr/metrics/reporters/SolrSlf4jReporterTest.java@@ -94,7 +94,7 @@ public class SolrSlf4jReporterTest extends SolrTestCaseJ4 {if (history.stream().filter(d -> "foobar".equals(d.getFirstValue("logger"))).count() == 0) {fail("No 'foobar' logs in: " + history.toString());}- if (history.stream().filter(d -> "x:collection1".equals(d.getFirstValue("core"))).count() == 0) {+ if (history.stream().filter(d -> "collection1".equals(d.getFirstValue("core"))).count() == 0) {fail("No 'solr.core' or MDC context in logs: " + history.toString());}}diff --git a/solr/docker/tests/cases/test_log4j/log4j2.xml b/solr/docker/tests/cases/test_log4j/log4j2.xmlindex 9a629595b13..5e319cc12be 100644--- a/solr/docker/tests/cases/test_log4j/log4j2.xml+++ b/solr/docker/tests/cases/test_log4j/log4j2.xml@@ -22,7 +22,7 @@<Console name="STDOUT" target="SYSTEM_OUT"><PatternLayout><Pattern>- %d{yyyy-MM-dd HH:mm:ss.SSS} %-5p (%t) [%X{collection} %X{shard} %X{replica} %X{core}] %c{1.} %m%n+ %d{yyyy-MM-dd HH:mm:ss.SSS} %-5p (%t) [%notEmpty{c:%X{collection}}%notEmpty{ s:%X{shard}}%notEmpty{ r:%X{replica}}%notEmpty{ x:%X{core}}] %c{1.} %m%n</Pattern></PatternLayout></Console>@@ -33,7 +33,7 @@filePattern="${sys:solr.log.dir}/solr.log.%i" ><PatternLayout><Pattern>- %d{yyyy-MM-dd HH:mm:ss.SSS} %-5p (%t) [%X{collection} %X{shard} %X{replica} %X{core}] %c{1.} %m%n+ %d{yyyy-MM-dd HH:mm:ss.SSS} %-5p (%t) [%notEmpty{c:%X{collection}}%notEmpty{ s:%X{shard}}%notEmpty{ r:%X{replica}}%notEmpty{ x:%X{core}}] %c{1.} %m%n</Pattern></PatternLayout><Policies>@@ -61,7 +61,7 @@filePattern="${sys:solr.log.dir}/solr_slow_requests.log.%i" ><PatternLayout><Pattern>- %d{yyyy-MM-dd HH:mm:ss.SSS} %-5p (%t) [%X{collection} %X{shard} %X{replica} %X{core}] %c{1.} %m%n+ %d{yyyy-MM-dd HH:mm:ss.SSS} %-5p (%t) [%notEmpty{c:%X{collection}}%notEmpty{ s:%X{shard}}%notEmpty{ r:%X{replica}}%notEmpty{ x:%X{core}}] %c{1.} %m%n</Pattern></PatternLayout><Policies>diff --git a/solr/server/resources/log4j2.xml b/solr/server/resources/log4j2.xmlindex 0a545b2a68c..4ec2fa2ecfb 100644--- a/solr/server/resources/log4j2.xml+++ b/solr/server/resources/log4j2.xml@@ -23,7 +23,7 @@<Console name="STDOUT" target="SYSTEM_OUT"><PatternLayout><Pattern>- %maxLen{%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p (%t) [%X{collection} %X{shard} %X{replica} %X{core}] %c{1.} %m%notEmpty{ =>%ex{short}}}{10240}%n+ %maxLen{%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p (%t) [%notEmpty{c:%X{collection}}%notEmpty{ s:%X{shard}}%notEmpty{ r:%X{replica}}%notEmpty{ x:%X{core}}] %c{1.} %m%notEmpty{ =>%ex{short}}}{10240}%n</Pattern></PatternLayout></Console>@@ -34,7 +34,7 @@filePattern="${sys:solr.log.dir}/solr.log.%i" ><PatternLayout><Pattern>- %maxLen{%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p (%t) [%X{collection} %X{shard} %X{replica} %X{core}] %c{1.} %m%notEmpty{ =>%ex{short}}}{10240}%n+ %maxLen{%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p (%t) [%notEmpty{c:%X{collection}}%notEmpty{ s:%X{shard}}%notEmpty{ r:%X{replica}}%notEmpty{ x:%X{core}}] %c{1.} %m%notEmpty{ =>%ex{short}}}{10240}%n</Pattern></PatternLayout><Policies>@@ -50,7 +50,7 @@filePattern="${sys:solr.log.dir}/solr_slow_requests.log.%i" ><PatternLayout><Pattern>- %maxLen{%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p (%t) [%X{collection} %X{shard} %X{replica} %X{core}] %c{1.} %m%notEmpty{ =>%ex{short}}}{10240}%n+ %maxLen{%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p (%t) [%notEmpty{c:%X{collection}}%notEmpty{ s:%X{shard}}%notEmpty{ r:%X{replica}}%notEmpty{ x:%X{core}}] %c{1.} %m%notEmpty{ =>%ex{short}}}{10240}%n</Pattern></PatternLayout><Policies>diff --git a/solr/solr-ref-guide/src/major-changes-in-solr-9.adoc b/solr/solr-ref-guide/src/major-changes-in-solr-9.adocindex 360edc421b3..c2e6933513c 100644--- a/solr/solr-ref-guide/src/major-changes-in-solr-9.adoc+++ b/solr/solr-ref-guide/src/major-changes-in-solr-9.adoc@@ -201,6 +201,13 @@ Users who upgrade from prior versions of Solr may find that some requests involvUser's in this situation are advised to consider the complexity f their queries/configuration, and increase the value of `<<configuring-solr-xml#global-maxbooleanclauses,maxBooleanClauses>>` if warranted.+=== Log4J configuration & Solr MDC values++link:http://www.slf4j.org/apidocs/org/slf4j/MDC.html[MDC] values that Solr sets for use by Logging calls (such as the collection name, shard name, replica name, etc...) have been modified to now be "bare" values, with out the special single character prefixes that were included in past version. For example: In 8.x Log messages for a collection named "gettingstarted" would have an MDC value with a key `collection` mapped to a value of `c:gettingstarted`, in 9.x the value will simply be `gettingstarted`.++Solr's default `log4j2.xml` configuration file has been modified to prepend these same prefixes to MDC values when included in Log messages as part of the `<PatternLayout/>`. Users who have custom logging configurations that wish to ensure Solr 9.x logs are consistently formatted after upgrading will need to make similar changes to their logging configuration files. See link:https://issues.apache.org/jira/browse/SOLR-15630[SOLR-15630] for more details.++=== base_url removed from stored stateIf you're able to upgrade SolrJ to 8.8.x for all of your client applications, then you can set `-Dsolr.storeBaseUrl=false` (introduced in Solr 8.8.1)diff --git a/solr/solrj/src/test-files/log4j2.xml b/solr/solrj/src/test-files/log4j2.xmlindex 57956155e27..96f69f1dc8b 100644--- a/solr/solrj/src/test-files/log4j2.xml+++ b/solr/solrj/src/test-files/log4j2.xml@@ -21,7 +21,7 @@<Console name="STDERR" target="SYSTEM_ERR"><PatternLayout><Pattern>- %maxLen{%-4r %-5p (%t) [%X{node_name} %X{collection} %X{shard} %X{replica} %X{core} %X{trace_id}] %c{1.} %m%notEmpty{+ %maxLen{%-4r %-5p (%t) [%notEmpty{n:%X{node_name}}%notEmpty{ c:%X{collection}}%notEmpty{ s:%X{shard}}%notEmpty{ r:%X{replica}}%notEmpty{ x:%X{core}}%notEmpty{ t:%X{trace_id}}] %c{1.} %m%notEmpty{=>%ex{short}}}{10240}%n</Pattern></PatternLayout>