No error emitted when using a YAML configuration without additional dependency
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
- Create a YAML configuration file named log4j2.yaml on the classpath turning on debug messages.
- Create a unit test getting the logger and logging an error message and a debug message.
- Observe only the error message during runtime.
Thank you.
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.
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
@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.
Ok, I will have a look at it.
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.