Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-2872

Unable to parse Custom Log Levels

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.13.3
    • None
    • Core
    • None

    Description

      When I set the logger level to custom value I get exception although my custom levels was created on init.  

      WARN Error while converting string [alert] to type [class org.apache.logging.log4j.Level]. Using default value [null]. java.lang.IllegalArgumentException: Unknown level constant [ALERT].

       

      The CustomLevel not added to Level.LEVELS ( ConcurrentMap<String, Level> LEVELS).

      My configuration:

      <Configuration status="DEBUG" monitorInterval="60">
          <Properties>
              <Property name="log-path">${cm.home}/../../proclog</Property
              <Property name="log-pattern">%d\{yyyy-MM-dd HH:mm:ss,SSS} %-2p [%t] (%logger\{1}:%L) - %m%n</Property>
          </Properties>
          <CustomLevels>
              <CustomLevel name="emerg" intLevel="0" />
              <CustomLevel name="alert" intLevel="1" />
              <CustomLevel name="crit" intLevel="2" />
              <CustomLevel name="err" intLevel="3" />
              <CustomLevel name="warning" intLevel="4" />
              <CustomLevel name="notice" intLevel="5" />
              <CustomLevel name="info" intLevel="6" />
              <CustomLevel name="debug" intLevel="7" />
          </CustomLevels>
          <Appenders>
              <Console name="Console-Appender" target="SYSTEM_OUT">
                  <PatternLayout pattern="${log-pattern}" />
              </Console>
      
              <RollingFile name="Alerts-Appender" fileName="${log-path}/alerts.log" filePattern="${log-path}/alerts%i.log">
                  <PatternLayout pattern="%date\{dd-MM-yy HH:mm:ss} | %level\{lowerCase=true} | %msg%n" />
                  <Policies>
                      <SizeBasedTriggeringPolicy size="10 MB" />
                  </Policies>
                  <DefaultRolloverStrategy fileIndex="min" max="5" />
              </RollingFile>
          </Appenders>
          <Loggers>
              <Logger name="ALERT_LOGGER" *level="alert"* additivity="false">
                  <AppenderRef ref="Alerts-Appender" />
                  <AppenderRef ref="Console-Appender" />
              </Logger>
              <Root level="debug">
                  <AppenderRef ref="Console-Appender" />
              </Root>
          </Loggers>
      </Configuration>
      

      Please see log in debug:

      2020-06-17 19:23:31,770 main DEBUG PluginManager 'Lookup' found 16 plugins
      2020-06-17 19:23:31,772 main DEBUG Building Plugin[name=CustomLevel, class=org.apache.logging.log4j.core.config.CustomLevelConfig].
      2020-06-17 19:23:31,773 main DEBUG createLevel(name="emerg", intLevel="0")
      2020-06-17 19:23:31,773 main DEBUG Creating CustomLevel(name='emerg', intValue=0)
      2020-06-17 19:23:31,774 main DEBUG Building Plugin[name=CustomLevel, class=org.apache.logging.log4j.core.config.CustomLevelConfig].
      2020-06-17 19:23:31,774 main DEBUG createLevel(name="alert", intLevel="1")
      2020-06-17 19:23:31,774 main DEBUG Creating CustomLevel(name='alert', intValue=1)
      2020-06-17 19:23:31,774 main DEBUG Building Plugin[name=CustomLevel, class=org.apache.logging.log4j.core.config.CustomLevelConfig].
      2020-06-17 19:23:31,775 main DEBUG createLevel(name="crit", intLevel="2")
      2020-06-17 19:23:31,775 main DEBUG Creating CustomLevel(name='crit', intValue=2)
      2020-06-17 19:23:31,775 main DEBUG Building Plugin[name=CustomLevel, class=org.apache.logging.log4j.core.config.CustomLevelConfig].
      2020-06-17 19:23:31,776 main DEBUG createLevel(name="err", intLevel="3")
      2020-06-17 19:23:31,776 main DEBUG Creating CustomLevel(name='err', intValue=3)
      2020-06-17 19:23:31,776 main DEBUG Building Plugin[name=CustomLevel, class=org.apache.logging.log4j.core.config.CustomLevelConfig].
      2020-06-17 19:23:31,776 main DEBUG createLevel(name="warning", intLevel="4")
      2020-06-17 19:23:31,777 main DEBUG Creating CustomLevel(name='warning', intValue=4)
      2020-06-17 19:23:31,777 main DEBUG Building Plugin[name=CustomLevel, class=org.apache.logging.log4j.core.config.CustomLevelConfig].
      2020-06-17 19:23:31,777 main DEBUG createLevel(name="notice", intLevel="5")
      2020-06-17 19:23:31,777 main DEBUG Creating CustomLevel(name='notice', intValue=5)
      2020-06-17 19:23:31,778 main DEBUG Building Plugin[name=CustomLevel, class=org.apache.logging.log4j.core.config.CustomLevelConfig].
      2020-06-17 19:23:31,778 main DEBUG createLevel(name="info", intLevel="6")
      2020-06-17 19:23:31,779 main DEBUG Creating CustomLevel(name='info', intValue=6)
      2020-06-17 19:23:31,779 main DEBUG Building Plugin[name=CustomLevel, class=org.apache.logging.log4j.core.config.CustomLevelConfig].
      2020-06-17 19:23:31,780 main DEBUG createLevel(name="debug", intLevel="7")
      2020-06-17 19:23:31,780 main DEBUG Creating CustomLevel(name='debug', intValue=7)
      2020-06-17 19:23:31,780 main DEBUG Building Plugin[name=CustomLevels, class=org.apache.logging.log4j.core.config.CustomLevels].
      2020-06-17 19:23:31,780 main DEBUG createCustomLevels(=\{CustomLevel[name=emerg, intLevel=0], CustomLevel[name=alert, intLevel=1], CustomLevel[name=crit, intLevel=2], CustomLevel[name=err, intLevel=3], CustomLevel[name=warning, intLevel=4], CustomLevel[name=notice, intLevel=5], CustomLevel[name=info, intLevel=6], CustomLevel[name=debug, intLevel=7]})
      
      ...
      
      2020-06-17 19:23:31,864 main WARN Error while converting string [alert] to type [class org.apache.logging.log4j.Level]. Using default value [null]. java.lang.IllegalArgumentException: Unknown level constant [ALERT].2020-06-17 19:23:31,864 main WARN Error while converting string [alert] to type [class org.apache.logging.log4j.Level]. Using default value [null]. java.lang.IllegalArgumentException: Unknown level constant [ALERT]. at org.apache.logging.log4j.Level.valueOf(Level.java:320) at org.apache.logging.log4j.core.config.plugins.convert.TypeConverters$LevelConverter.convert(TypeConverters.java:288) at org.apache.logging.log4j.core.config.plugins.convert.TypeConverters$LevelConverter.convert(TypeConverters.java:284) at org.apache.logging.log4j.core.config.plugins.convert.TypeConverters.convert(TypeConverters.java:419) at org.apache.logging.log4j.core.config.plugins.visitors.AbstractPluginVisitor.convert(AbstractPluginVisitor.java:149) at org.apache.logging.log4j.core.config.plugins.visitors.PluginAttributeVisitor.visit(PluginAttributeVisitor.java:45) at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.generateParameters(PluginBuilder.java:258) at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:135) at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:1002) at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:942) at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:934) at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:552) at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:241) at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:288) at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:618) at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:691) at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:708) at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:263) at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:153) at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45) at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194) at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext(AbstractLoggerAdapter.java:138) at org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:45) at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:48) at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:30) at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:358) at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383) 
      
       
      
      2020-06-17 19:23:31,866 main DEBUG createLogger(additivity="false", level="null", name="com.bmc.ctm.saas.alerts", includeLocation="null", =\{Alerts-Appender, Console-Appender}, ={}, Configuration(C:\Bitbucket\saas-alerts-collector\target\classes\log4j2.xml), Filter=null)
      

      Attachments

        Issue Links

          Activity

            People

              pkarwasz Piotr Karwasz
              AllaG Alla Gofman
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: