Problem with configuring loggers via LogConfigurator



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("", "rolling")
                                          .put("appender.rolling.fileName", "D:\\eslog.log")
                                          .put("appender.rolling.layout.type", "PatternLayout")
                                          .put("logger.level", "INFO")
                                          .put("logger.appenderRefs", "rolling")

        return InternalSettingsPreparer.prepareSettings(settings);

and I pass this to LogConfigurator:


However, I get this:

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

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.

(Jason Tedor) #2

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 (and use LogConfigurator#configure).

(system) #3

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