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

Using Configurator.setLevel() results in a default LoggerConfig

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Invalid
    • Affects Version/s: 2.8.2
    • Fix Version/s: None
    • Component/s: Configurators
    • Labels:
      None

      Description

      Using Configurator.setLevel(String, Level) to change log level of a logger results in a new LoggerConfig if non exists before.
      This appear to result in a config with out an Appender.

      Is this desired behavior and what are the side effects of this?

      Could a solution be to inherit the Appender or AppenderRefs from the parent logger/config?

      Code in question from org.apache.logging.log4j.core.config.Configurator

      private static boolean setLevel(final String loggerName, final Level level, final Configuration config) {
              boolean set;
              LoggerConfig loggerConfig = config.getLoggerConfig(loggerName);
              if (!loggerName.equals(loggerConfig.getName())) {
                  // TODO Should additivity be inherited?
                  loggerConfig = new LoggerConfig(loggerName, level, true);
                  config.addLogger(loggerName, loggerConfig);
                  loggerConfig.setLevel(level);
                  set = true;
              } else {
                  set = setLevel(loggerConfig, level);
              }
              return set;
          }
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              oganga Thorkild Gregersen
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: