apache / logging-log4j2

Apache Log4j 2 is a versatile, feature-rich, efficient logging API and backend for Java.
https://logging.apache.org/log4j/2.x/
Apache License 2.0
3.34k stars 1.59k forks source link

No error emitted when using a YAML configuration without additional dependency #1501

Open designatevoid opened 1 year ago

designatevoid commented 1 year ago

Description

The software ignores YAML configuration silently if YAML configuration is used with the dependencies specified on the Maven, Ivy Gradle Artifacts page (log4j-api and log4j-core) but not with the Jackson Databind and YAML Data Format dependencies.

Configuration

Version: 2.20.0

Operating system: Windows 11 (build 22621.1702)

JDK: openjdk 19.0.2 2023-01-17

Logs

None, no warning about using default configurations or being unable to process a log4j2.yaml file found on the classpath.

Reproduction

  1. Create a YAML configuration file named log4j2.yaml on the classpath turning on debug messages.
  2. Create a unit test getting the logger and logging an error message and a debug message.
  3. Observe only the error message during runtime.

Thank you.

rgoers commented 1 year ago

The call to getConfiguration returns null when dependencies are missing. We should probably log a warning as the method wouldn't have been called if the configuration file wasn't of a supported type.

lukaszspyra commented 1 year ago

Hi @rgoers , I've done some checks with a/m setup, and looks like there are StatusLogger messages for missing dependencies (DEBUG) and using default config (WARN), however it requires setting system property log4j2.debug:

DEBUG StatusLogger Missing dependencies for Yaml support, ConfigurationFactory org.apache.logging.log4j.core.config.yaml.YamlConfigurationFactory is inactive DEBUG StatusLogger Missing dependencies for Json support, ConfigurationFactory org.apache.logging.log4j.core.config.json.JsonConfigurationFactory is inactive

followed by:

WARN StatusLogger Found configuration file log4j2.yaml for inactive ConfigurationFactory org.apache.logging.log4j.core.config.yaml.YamlConfigurationFactory WARN StatusLogger No Log4j 2 configuration file found. Using default configuration (logging only errors to the console), or user programmatically provided configurations. Set system property 'log4j2.debug' to show Log4j 2 internal initialization logging. See https://logging.apache.org/log4j/2.x/manual/configuration.html for instructions on how to configure Log4j 2

ppkarwasz commented 1 year ago

@lukaszspyra,

Yes, you are right, the warnings are there, but they are disabled by default.

We should probably bump the level of both the StatusLogger (which is used when no configuration is active) and StatusConfiguration (which the default value of a configuration's status attribute) to WARN.

lukaszspyra commented 1 year ago

Ok, I will have a look at it.

lukaszspyra commented 1 year ago

Hi @ppkarwasz, Could you please have a look on the draft PR? Especially point 3 regarding AbstractConfiguration, as it is used by many subclasses. Still need to do some tests, unit would be difficult (StatusLogger singleton/no accessors in StatusConfiguration), so will try integration with dummy config files.