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

fix toString() method in configuration implementations (apache#3599)

Open anindita-sarkarArray opened this issue 8 months ago • 5 comments

Added toString implementation to AbstractConfiguration and removed from all derived classes.

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

Why? This makes debugging worse as we loosing information.

garydgregory avatar May 11 '25 12:05 garydgregory

Why? This makes debugging worse as we loosing information.

hi @garydgregory , instead of AbstractConfiguration , shall I put my changes to all derived classes so that it can retain the additional info of subclasses.

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

Job Requested goals Build Tool Version Build Outcome Build Scan®
build-macos-latest clean install 3.9.8 :white_check_mark: Build Scan PUBLISHED
build-ubuntu-latest clean install 3.9.8 :white_check_mark: Build Scan PUBLISHED
build-windows-latest clean install 3.9.8 :white_check_mark: Build Scan PUBLISHED

Generated by gradle/develocity-actions

github-actions[bot] avatar May 11 '25 17:05 github-actions[bot]

I am still -1 here: toString() is for debugging. If a call site needs a different view on the object, then it can call another method on that object or build that view (like a String) itself.

garydgregory avatar May 20 '25 19:05 garydgregory

Hi @anindita-sarkarArray,

I discussed this with @garydgregory, and I agree that the toString() methods should remain unchanged to preserve a better debugging experience within IDEs.

Following the discussion in #3100, I also think it's a good idea to reduce verbosity in Log4j Core by default. With that in mind, I propose the following:

  1. Downgrade the log level of the INFO messages I added in LoggerContext and AbstractConfiguration to DEBUG, with one exception:

    • Keep the INFO message at: https://github.com/apache/logging-log4j2/blob/422c385dc9450d4f620a23d84abe2d6a0aa5b9fb/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java#L328-L334
  2. Add an INFO message in LoggerContext.setConfiguration(Configuration) to notify users when a new configuration becomes active (i.e., after the updateLoggers() call). The message could be formatted like:

    <logger_context_class_name>[name=<name>] is using <configuration_class_name>[location=<location>, lastModified=<last_modified>].
    

Let me know what you think.

ppkarwasz avatar Jun 16 '25 11:06 ppkarwasz