@Override protected void registerDerivedNodeNameWithLogger(String nodeName) { LogConfigurator.setNodeName(nodeName); }
/** * Configure logging without reading a log4j2.properties file, effectively configuring the * status logger and all loggers to the console. * * @param settings for configuring logger.level and individual loggers */ public static void configureWithoutConfig(final Settings settings) { Objects.requireNonNull(settings); // we initialize the status logger immediately otherwise Log4j will complain when we try to get the context configureStatusLogger(); configureLoggerLevels(settings); }
/** * Configures logging without Elasticsearch configuration files based on the system property "es.logger.level" only. As such, any * logging will be written to the console. */ static void configureLoggingWithoutConfig() { // initialize default for es.logger.level because we will not read the log4j2.properties final String loggerLevel = System.getProperty("es.logger.level", Level.INFO.name()); final Settings settings = Settings.builder().put("logger.level", loggerLevel).build(); LogConfigurator.configureWithoutConfig(settings); }
Objects.requireNonNull(logsPath); loadLog4jPlugins(); setLogConfigurationSystemProperty(logsPath, settings); configureStatusLogger(); configureLoggerLevels(settings);
private static void configure(final Settings settings, final Path configsPath, final Path logsPath) throws IOException, UserException { Objects.requireNonNull(settings); Objects.requireNonNull(configsPath); Objects.requireNonNull(logsPath); setLogConfigurationSystemProperty(logsPath, settings); // we initialize the status logger immediately otherwise Log4j will complain when we try to get the context configureStatusLogger(); final LoggerContext context = (LoggerContext) LogManager.getContext(false); final List<AbstractConfiguration> configurations = new ArrayList<>(); final PropertiesConfigurationFactory factory = new PropertiesConfigurationFactory(); final Set<FileVisitOption> options = EnumSet.of(FileVisitOption.FOLLOW_LINKS); Files.walkFileTree(configsPath, options, Integer.MAX_VALUE, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { if (file.getFileName().toString().equals("log4j2.properties")) { configurations.add((PropertiesConfiguration) factory.getConfiguration(context, file.toString(), file.toUri())); } return FileVisitResult.CONTINUE; } }); if (configurations.isEmpty()) { throw new UserException( ExitCodes.CONFIG, "no log4j2.properties found; tried [" + configsPath + "] and its subdirectories"); } context.start(new CompositeConfiguration(configurations)); warnIfOldConfigurationFilePresent(configsPath); configureLoggerLevels(settings); }
LogConfigurator.setNodeName(Node.NODE_NAME_SETTING.get(environment.settings())); LogConfigurator.configure(environment); } catch (IOException e) { throw new BootstrapException(e);
/** * Configure logging reading from any log4j2.properties found in the config directory and its * subdirectories from the specified environment. Will also configure logging to point the logs * directory from the specified environment. * * @param environment the environment for reading configs and the logs path * @throws IOException if there is an issue readings any log4j2.properties in the config * directory * @throws UserException if there are no log4j2.properties in the specified configs path */ public static void configure(final Environment environment) throws IOException, UserException { Objects.requireNonNull(environment); try { // we are about to configure logging, check that the status logger did not log any error-level messages checkErrorListener(); } finally { // whether or not the error listener check failed we can remove the listener now StatusLogger.getLogger().removeListener(ERROR_LISTENER); } configure(environment.settings(), environment.configFile(), environment.logsFile()); }
try { checkErrorListener(); } finally { configure(environment.settings(), environment.configFile(), environment.logsFile()); Objects.requireNonNull(logsPath); setLogConfigurationSystemProperty(logsPath, settings);
/** * Main entry point for starting elasticsearch */ public static void main(final String[] args) throws Exception { overrideDnsCachePolicyProperties(); /* * We want the JVM to think there is a security manager installed so that if internal policy decisions that would be based on the * presence of a security manager or lack thereof act as if there is a security manager present (e.g., DNS cache policy). This * forces such policies to take effect immediately. */ System.setSecurityManager(new SecurityManager() { @Override public void checkPermission(Permission perm) { // grant all permissions so that we can later set the security manager to the one that we want } }); LogConfigurator.registerErrorListener(); final Elasticsearch elasticsearch = new Elasticsearch(); int status = main(args, elasticsearch, Terminal.DEFAULT); if (status != ExitCodes.OK) { exit(status); } }
final Environment environment = new Environment(settings, confPath); if (!disableESLogger) { LogConfigurator.registerErrorListener(); LogConfigurator.configure(environment);
private static void checkErrorListener() { assert errorListenerIsRegistered() : "expected error listener to be registered"; if (error.get()) { throw new IllegalStateException("status logger logged an error before logging was configured"); } }
final Environment environment = createEnvironment(foreground, pidFile, keystore, initialEnv.settings(), initialEnv.configFile()); try { LogConfigurator.configure(environment); } catch (IOException e) { throw new BootstrapException(e);
Objects.requireNonNull(logsPath); loadLog4jPlugins(); setLogConfigurationSystemProperty(logsPath, settings); configureStatusLogger(); configureLoggerLevels(settings);
LogConfigurator.setNodeName(Node.NODE_NAME_SETTING.get(environment.settings())); LogConfigurator.configure(environment); } catch (IOException e) { throw new BootstrapException(e);
/** * Configure logging reading from any log4j2.properties found in the config directory and its * subdirectories from the specified environment. Will also configure logging to point the logs * directory from the specified environment. * * @param environment the environment for reading configs and the logs path * @throws IOException if there is an issue readings any log4j2.properties in the config * directory * @throws UserException if there are no log4j2.properties in the specified configs path */ public static void configure(final Environment environment) throws IOException, UserException { Objects.requireNonNull(environment); try { // we are about to configure logging, check that the status logger did not log any error-level messages checkErrorListener(); } finally { // whether or not the error listener check failed we can remove the listener now StatusLogger.getLogger().removeListener(ERROR_LISTENER); } configure(environment.settings(), environment.configFile(), environment.logsFile()); }
/** * Main entry point for starting elasticsearch */ public static void main(final String[] args) throws Exception { // we want the JVM to think there is a security manager installed so that if internal policy decisions that would be based on the // presence of a security manager or lack thereof act as if there is a security manager present (e.g., DNS cache policy) System.setSecurityManager(new SecurityManager() { @Override public void checkPermission(Permission perm) { // grant all permissions so that we can later set the security manager to the one that we want } }); LogConfigurator.registerErrorListener(); final Elasticsearch elasticsearch = new Elasticsearch(); int status = main(args, elasticsearch, Terminal.DEFAULT); if (status != ExitCodes.OK) { exit(status); } }
private static void checkErrorListener() { assert errorListenerIsRegistered() : "expected error listener to be registered"; if (error.get()) { throw new IllegalStateException("status logger logged an error before logging was configured"); } }
Environment environment = createEnvironment(foreground, pidFile, keystore, initialEnv.settings()); try { LogConfigurator.configure(environment); } catch (IOException e) { throw new BootstrapException(e);
/** * Configure logging reading from any log4j2.properties found in the config directory and its * subdirectories from the specified environment. Will also configure logging to point the logs * directory from the specified environment. * * @param environment the environment for reading configs and the logs path * @throws IOException if there is an issue readings any log4j2.properties in the config * directory * @throws UserException if there are no log4j2.properties in the specified configs path */ public static void configure(final Environment environment) throws IOException, UserException { Objects.requireNonNull(environment); try { // we are about to configure logging, check that the status logger did not log any error-level messages checkErrorListener(); } finally { // whether or not the error listener check failed we can remove the listener now StatusLogger.getLogger().removeListener(ERROR_LISTENER); } configure(environment.settings(), environment.configFile(), environment.logsFile()); }
/** * Configure logging without reading a log4j2.properties file, effectively configuring the * status logger and all loggers to the console. * * @param settings for configuring logger.level and individual loggers */ public static void configureWithoutConfig(final Settings settings) { Objects.requireNonNull(settings); // we initialize the status logger immediately otherwise Log4j will complain when we try to get the context configureStatusLogger(); configureLoggerLevels(settings); }