ppkarwasz commented on issue #2281: URL: https://github.com/apache/logging-log4j2/issues/2281#issuecomment-2561710942
> > The main difference between the [core.Logger#setLevel](https://logging.apache.org/log4j/2.x/javadoc/log4j-core/org/apache/logging/log4j/core/Logger.html#setLevel(org.apache.logging.log4j.Level)) method and [Configurator#setLevel](https://logging.apache.org/log4j/2.x/javadoc/log4j-core/org/apache/logging/log4j/core/config/Configurator.html#setLevel(org.apache.logging.log4j.Logger,org.apache.logging.log4j.Level)) is that the former changes only the level of a specific logger, while the latter also changes the level of child loggers. > > Sorry for making noise on this closed issue. Out of curiosity, what is the difference between `Configurator#setLevel` and `Configurator.setAllLevels` - it seems both of they can change the level of child loggers. To understand the difference between the two methods, you should take a closer look at the [architecture of Log4j Core](https://logging.apache.org/log4j/2.x/manual/architecture.html). There are two types of objects: - [`Logger`s](https://logging.apache.org/log4j/2.x/javadoc/log4j-core/org/apache/logging/log4j/core/Logger.html) that you create using: ```java Logger foo = LogManager.getLogger("foo"); Logger fooBar = LogManager.getLogger("foo.bar"); Logger fooBarBaz = LogManager.getLogger("foo.bar.baz"); ``` - [`LoggerConfig`s](https://logging.apache.org/log4j/2.x/javadoc/log4j-core/org/apache/logging/log4j/core/config/LoggerConfig.html) that you create using the `<Logger>` elements in a configuration file, e.g.: ```xml <Logger name="foo" level="ERROR"/> <Logger name="foo.bar.baz" level="WARN"/> ``` Multiple `Logger`s can be attached to a single `LoggerConfig`. In the example above the "foo" and "foo.bar" loggers are both attached to the "foo" logger configuration, while the "foo.bar.baz" logger is attached to the "foo.bar.baz" logger configuration. The `Configurator` API only works on logger configurations: - if you call `Configurator.setLevel("foo", Level.INFO)`, you'll modify the effective level of the loggers attached to the "foo" `LoggerConfig` (i.e. the "foo" and "foo.bar" loggers). - if you call `Configurator.setAllLevels("foo", Level.INFO)`, you'll modify both the "foo" and "foo.bar.baz" `LoggerConfig`s. This will change the effective level of the "foo", "foo.bar" and "foo.bar.baz" loggers. The situation becomes slightly more complex if you take into account the **inheritance** of levels between `LoggerConfig`s. If the "foo.bar.baz" logger configuration has a `null` level, it inherits the effective level from its parent (the "foo" `LoggerConfig`). In this case, calling `Configurator.setLevel("foo", Level.INFO)` will also change the effective level of the "foo.bar.baz" logger. > By constrast, `setLevel` can change only the programmatically logger as they don't have `LoggerConfig`. If a logger (like "foo.bar" above) does not have a `LoggerConfig` with the same name, both `Configurator.setLevel()` and `Configurator.setAllLevels()` will create a new `LoggerConfig`. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org