Hi all,

I am currently struggling with my custom log levels (with Log4J version 2.14.1):

I added three levels (MSG, WRN, ERR) corresponding to existing levels in our 
previous logging solution, but with the same numeric level values as the Log4J 
2 levels INFO, WARN, ERROR.
These levels are created in my generated custom logger using 
"Level.forName(...)".

Unfortunately using the (minimal) configuration below I get an "Error while 
converting string [msg] to type [class org.apache.logging.log4j.Level]. Using 
default value [null]. java.lang.IllegalArgumentException: Unknown level 
constant [MSG]"

Config:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
  <Appenders>
    <Console name="AppConsole" target="SYSTEM_OUT">
      <MyCompanyLayout/>
    </Console>
  </Appenders>
  <Loggers>
    <Logger name="applog" level="msg">
      <AppenderRef ref="AppConsole"/>
    </Logger>
  </Loggers>
</Configuration>

When I add

<CustomLevels>
  <CustomLevel name="ERR" intLevel="200" />
  <CustomLevel name="WRN" intLevel="300" />
  <CustomLevel name="MSG" intLevel="400" />
</CustomLevels>

it works without any issues, however I would like to programmatically add these 
levels since we want to provide our logger as an internal API and I don't want 
every user to additionally include this configuration.
I tried defining a ConfigurationFactory plugin that adds these levels to the 
loaded configuration as described in "Initialize Log4j by Combining 
Configuration File with Programmatic Configuration" by calling 
getCustomLevels.add(...) but since this is an unmodifiable list the 
configuration fails.

Any ideas how I could achieve this?

Thanks in advance for the help and providing such a refined log framework!

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org

Reply via email to