Skip to content

Commit

Permalink
Add setting for disabling console logging
Browse files Browse the repository at this point in the history
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 elastic#95295
  • Loading branch information
rjernst committed Nov 27, 2024
1 parent 9022ccc commit d8b0290
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -84,6 +85,8 @@ public void log(StatusData data) {

private static Appender consoleAppender;

public static final Setting<Boolean> 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit d8b0290

Please sign in to comment.