Problem with configuring loggers via LogConfigurator

Hi,

I am trying to add rolling file appender to logger using LogConfigurator. Right now I have some code prototype and part of basic log4j2 settings:

private static Settings logSettings() {
        final Settings settings = Settings.builder()
                                          .put("appender.rolling.type", "RollingFile")
                                          .put("appender.rolling.name", "rolling")
                                          .put("appender.rolling.fileName", "D:\\eslog.log")
                                          .put("appender.rolling.layout.type", "PatternLayout")
                                          .put("logger.level", "INFO")
                                          .put("logger.appenderRefs", "rolling")
                                          .build();

        return InternalSettingsPreparer.prepareSettings(settings);
    }

and I pass this to LogConfigurator:

        LogConfigurator.configureWithoutConfig(logSettings());

However, I get this:

Exception in thread "main" java.lang.IllegalArgumentException: Unknown level constant [ROLLING].
	at org.apache.logging.log4j.Level.valueOf(Level.java:314)
	at org.elasticsearch.common.settings.Setting.get(Setting.java:323)
	at org.elasticsearch.common.logging.LogConfigurator.configureLoggerLevels(LogConfigurator.java:144)
	at org.elasticsearch.common.logging.LogConfigurator.configureWithoutConfig(LogConfigurator.java:69)
	at es5test.es5.App.main(App.java:38)

After doing some debugging it looks for me like a problem with ESLoggerFactory.LOG_LEVEL_SETTING which seems to match every key starting with "logger". I am new to ElasticSearch and configuring log4j2, so I wanted to ask if I am doing something some mistake or if it's really a bug?

I will appreciate any help.

You can not configure logging programmatically through LogConfigurator like this, only logging levels. If you want to configure logging through LogConfigurator, you have to use log4j2.properties (and use LogConfigurator#configure).

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.