File tree Expand file tree Collapse file tree
server/src/main/java/org/elasticsearch Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2727 * Holder class for method to configure logging without Elasticsearch configuration files for use in CLI tools that will not read such
2828 * files.
2929 */
30- final class CommandLoggingConfigurator {
30+ public final class CommandLoggingConfigurator {
3131
3232 /**
3333 * Configures logging without Elasticsearch configuration files based on the system property "es.logger.level" only. As such, any
3434 * logging will be written to the console.
3535 */
36- static void configureLoggingWithoutConfig () {
36+ public static void configureLoggingWithoutConfig () {
3737 // initialize default for es.logger.level because we will not read the log4j2.properties
3838 final String loggerLevel = System .getProperty ("es.logger.level" , Level .INFO .name ());
3939 final Settings settings = Settings .builder ().put ("logger.level" , loggerLevel ).build ();
Original file line number Diff line number Diff line change 1818 */
1919package org .elasticsearch .cluster .coordination ;
2020
21- import org .elasticsearch .cli .LoggingAwareMultiCommand ;
21+ import org .elasticsearch .cli .CommandLoggingConfigurator ;
22+ import org .elasticsearch .cli .MultiCommand ;
2223import org .elasticsearch .cli .Terminal ;
2324
24- public class NodeToolCli extends LoggingAwareMultiCommand {
25+ // NodeToolCli does not extend LoggingAwareCommand, because LoggingAwareCommand performs logging initialization
26+ // after LoggingAwareCommand instance is constructed.
27+ // It's too late for us, because before UnsafeBootstrapMasterCommand is added to the list of subcommands
28+ // log4j2 initialization will happen, because it has static reference to Logger class.
29+ // Even if we avoid making a static reference to Logger class, there is no nice way to avoid declaring
30+ // UNSAFE_BOOTSTRAP, which depends on ClusterService, which in turn has static Logger.
31+ // TODO execute CommandLoggingConfigurator.configureLoggingWithoutConfig() in the constructor of commands, not in beforeMain
32+ public class NodeToolCli extends MultiCommand {
2533
2634 public NodeToolCli () {
27- super ("A CLI tool to unsafely recover a cluster after the permanent loss of too many master-eligible nodes" );
35+ super ("A CLI tool to unsafely recover a cluster after the permanent loss of too many master-eligible nodes" , ()->{});
36+ CommandLoggingConfigurator .configureLoggingWithoutConfig ();
2837 subcommands .put ("unsafe-bootstrap" , new UnsafeBootstrapMasterCommand ());
2938 }
3039
Original file line number Diff line number Diff line change 4646
4747public class UnsafeBootstrapMasterCommand extends EnvironmentAwareCommand {
4848
49+ private static final Logger logger = LogManager .getLogger (UnsafeBootstrapMasterCommand .class );
4950 private final NamedXContentRegistry namedXContentRegistry ;
5051
5152 static final String WARNING_MSG =
@@ -81,9 +82,6 @@ public class UnsafeBootstrapMasterCommand extends EnvironmentAwareCommand {
8182
8283 @ Override
8384 protected void execute (Terminal terminal , OptionSet options , Environment env ) throws Exception {
84- // We don't use classical "private static final Logger", because log4j2 initialization happens
85- // after UnsafeBootstrapMasterCommand instance creation.
86- final Logger logger = LogManager .getLogger (UnsafeBootstrapMasterCommand .class );
8785 showWarning (terminal );
8886 String text = terminal .readText ("Confirm [y/N] " );
8987 if (text .equalsIgnoreCase ("y" ) == false ) {
You can’t perform that action at this time.
0 commit comments