logging-log4j2 icon indicating copy to clipboard operation
logging-log4j2 copied to clipboard

Fix `toString()` method in configuration implementations

Open ppkarwasz opened this issue 8 months ago • 3 comments

Description

PR #2941 introduces some basic logging of the most important Configuration lifecycle events at an INFO level. The messages are meant to convey:

  • which configuration file is used.
  • the last modification timestamp of the file to distinguish between two revisions of the same file.

Unfortunately this information only appears in XmlConfiguration:

https://github.com/apache/logging-log4j2/blob/86781fd8a7d8c07509ba9e430c08333fd82f34bf/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java#L340-L343

JsonConfiguration only prints the name of the configuration file, while PropertiesConfiguration does not have a toString() method at all:

2025-04-04T19:10:16.058147325Z pool-10-thread-1 INFO Stopping configuration org.apache.logging.log4j.core.config.properties.PropertiesConfiguration@18765d9b...
2025-04-04T19:10:16.058147313Z pool-9-thread-1 INFO Stopping configuration org.apache.logging.log4j.core.config.properties.PropertiesConfiguration@18f5f66d...
2025-04-04T19:10:16.058631896Z pool-10-thread-1 INFO Configuration org.apache.logging.log4j.core.config.properties.PropertiesConfiguration@18765d9b stopped.
2025-04-04T19:10:16.058880638Z pool-9-thread-1 INFO Configuration org.apache.logging.log4j.core.config.properties.PropertiesConfiguration@18f5f66d stopped.

We probably should add the toString() method to AbstractConfiguration and remove it from its derived classes.

ppkarwasz avatar Apr 10 '25 17:04 ppkarwasz

@ppkarwasz I have made the requested changes. https://github.com/apache/logging-log4j2/pull/3658 Please review

anindita-sarkarArray avatar May 11 '25 12:05 anindita-sarkarArray

Why? This is not better since are now loosing information that was previously provided.

garydgregory avatar May 11 '25 12:05 garydgregory

hi @garydgregory , instead of AbstractConfiguration , shall I put my changes to all derived classes so that it can retain the additional info of subclasses. OR in addition to adding in AbstractConfiguration, I will modify the subclasses already having toString to have additional properties like [location=" + getConfigurationSource() + ", lastModified=" + Instant.ofEpochMilli(getConfigurationSource().getLastModified())

anindita-sarkarArray avatar May 11 '25 12:05 anindita-sarkarArray