From d8b029001983e4d1b88286d4bf6c529acb2eb156 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Wed, 27 Nov 2024 13:16:51 -0800 Subject: [PATCH 1/2] Add setting for disabling console logging This commit adds an explicit setting for disabling console logging, instead only writing to the main application log file. The setting name chosen sets up a pattern for future logging configuration of files, using the `logging.` prefix, followed by the log, and then the log specific setting, in this case whether it is enabled. see https://github.com/elastic/elasticsearch/issues/95295 --- .../main/java/org/elasticsearch/bootstrap/Elasticsearch.java | 5 +++-- .../org/elasticsearch/common/logging/LogConfigurator.java | 3 +++ .../org/elasticsearch/common/settings/ClusterSettings.java | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java b/server/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java index b7774259bf289..a4165b12348b2 100644 --- a/server/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java +++ b/server/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java @@ -137,9 +137,10 @@ public void checkPermission(Permission perm) { BootstrapInfo.setConsole(ConsoleLoader.loadConsole(nodeEnv)); // DO NOT MOVE THIS - // Logging must remain the last step of phase 1. Anything init steps needing logging should be in phase 2. + // Logging must remain the last step of phase 1. Any init steps needing logging should be in phase 2. LogConfigurator.setNodeName(Node.NODE_NAME_SETTING.get(args.nodeSettings())); - LogConfigurator.configure(nodeEnv, args.quiet() == false); + boolean console = args.quiet() == false && LogConfigurator.CONSOLE_ENABLED.get(args.nodeSettings()); + LogConfigurator.configure(nodeEnv, console); } catch (Throwable t) { // any exception this early needs to be fully printed and fail startup t.printStackTrace(err); diff --git a/server/src/main/java/org/elasticsearch/common/logging/LogConfigurator.java b/server/src/main/java/org/elasticsearch/common/logging/LogConfigurator.java index f6d6c7fd68738..5b4564bf46fff 100644 --- a/server/src/main/java/org/elasticsearch/common/logging/LogConfigurator.java +++ b/server/src/main/java/org/elasticsearch/common/logging/LogConfigurator.java @@ -36,6 +36,7 @@ import org.apache.logging.log4j.util.Unbox; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.common.logging.internal.LoggerFactoryImpl; +import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.core.SuppressForbidden; import org.elasticsearch.env.Environment; @@ -84,6 +85,8 @@ public void log(StatusData data) { private static Appender consoleAppender; + public static final Setting CONSOLE_ENABLED = Setting.boolSetting("logging.console.enabled", true, Setting.Property.NodeScope); + /** * Registers a listener for status logger errors. This listener should be registered as early as possible to ensure that no errors are * logged by the status logger before logging is configured. diff --git a/server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java b/server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java index a9a9411de8e1f..58eab6145d337 100644 --- a/server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java +++ b/server/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java @@ -60,6 +60,7 @@ import org.elasticsearch.cluster.service.ClusterApplierService; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.cluster.service.MasterService; +import org.elasticsearch.common.logging.LogConfigurator; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.network.NetworkService; @@ -479,6 +480,7 @@ public void apply(Settings value, Settings current, Settings previous) { Node.NODE_EXTERNAL_ID_SETTING, Node.NODE_NAME_SETTING, Node.NODE_ATTRIBUTES, + LogConfigurator.CONSOLE_ENABLED, NodeRoleSettings.NODE_ROLES_SETTING, AutoCreateIndex.AUTO_CREATE_INDEX_SETTING, BaseRestHandler.MULTI_ALLOW_EXPLICIT_INDEX, From e33b50f2e56de079f8a3097959f959582cac6f1c Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Wed, 27 Nov 2024 13:20:56 -0800 Subject: [PATCH 2/2] Update docs/changelog/117665.yaml --- docs/changelog/117665.yaml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 docs/changelog/117665.yaml diff --git a/docs/changelog/117665.yaml b/docs/changelog/117665.yaml new file mode 100644 index 0000000000000..431fa6d0153c8 --- /dev/null +++ b/docs/changelog/117665.yaml @@ -0,0 +1,5 @@ +pr: 117665 +summary: Add setting for disabling console logging +area: Infra/Logging +type: enhancement +issues: []