Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-2023

Use a class' canonical name instead of name to create its logger name

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.9.0, 2.9.1
    • Component/s: API
    • Labels:
      None

      Description

      Use a class' canonical name instead of name to create its logger name.

      Say you have loggers built with Classes for which getName() give you:

      • com.example.app.A
      • com.example.app.A$AS1
      • com.example.app.A$AS2
      • ...
      • com.example.app.A$ASN

      Before 2.9.0: You you set the root logger to WARN and com.example.app.A to INFO, then you get INFO events for A but you do not get INFO messages from AS1, AS2, and so on. There is no way to set all A$ASx loggers to the same level at the same time.

      In 2.9.0 now, converting a Class to a logger name uses getCannonicalName() such that the logger names are:

      • com.example.app.A
      • com.example.app.A.AS1
      • com.example.app.A.AS2
      • ...
      • com.example.app.A.ASN

      When you set com.example.app.A to INFO, then you get INFO events for A, AS1, AS2, and so on.

      The dev ML thread is:

      https://lists.apache.org/thread.html/43b83474aad9c8625e5a6a63d2595c9d795dd6a51076493bacd87a36@%3Cdev.logging.apache.org%3E

      Note post 2.9.0: If the class canonical name is null, then use the class name.

        Issue Links

          Activity

          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit b78cb76737b7ec42abd9b2330243aa6d58bb9cb3 in logging-log4j2's branch refs/heads/master from Gary Gregory
          [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=b78cb76 ]

          LOG4J2-2023 Use a class' canonical name instead of name to create its
          logger name.

          Show
          jira-bot ASF subversion and git services added a comment - Commit b78cb76737b7ec42abd9b2330243aa6d58bb9cb3 in logging-log4j2's branch refs/heads/master from Gary Gregory [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=b78cb76 ] LOG4J2-2023 Use a class' canonical name instead of name to create its logger name.
          Hide
          garydgregory Gary Gregory added a comment -

          In Git master.

          Show
          garydgregory Gary Gregory added a comment - In Git master.
          Hide
          remkop@yahoo.com Remko Popma added a comment -

          As discussed in the mailing list, the user manual needs to be updated for this change:

          Ok, let's document this clearly though.

          There may be users that have configuration to route logging from an inner
          class to a separate appender. If I'm not mistaken our change will break
          such configurations.

          Show
          remkop@yahoo.com Remko Popma added a comment - As discussed in the mailing list, the user manual needs to be updated for this change: Ok, let's document this clearly though. There may be users that have configuration to route logging from an inner class to a separate appender. If I'm not mistaken our change will break such configurations.
          Hide
          jasontedor Jason Tedor added a comment -

          Would you please link to the relevant mailing list discussion? I have looked on the [user list](http://mail-archives.apache.org/mod_mbox/logging-log4j-user/) and the [dev list](http://mail-archives.apache.org/mod_mbox/logging-log4j-dev/) (which for some reason is only archived through April) and have not successfully found it. I also looked at the commit log. I would like to understand the reasoning behind this breaking change. In particular, was the impact this would have on local and anonymous classes considered?

          I think the entire community would benefit from more verbose descriptions of reasoning on issues and in commit messages.

          Show
          jasontedor Jason Tedor added a comment - Would you please link to the relevant mailing list discussion? I have looked on the [user list] ( http://mail-archives.apache.org/mod_mbox/logging-log4j-user/ ) and the [dev list] ( http://mail-archives.apache.org/mod_mbox/logging-log4j-dev/ ) (which for some reason is only archived through April) and have not successfully found it. I also looked at the commit log. I would like to understand the reasoning behind this breaking change. In particular, was the impact this would have on local and anonymous classes considered? I think the entire community would benefit from more verbose descriptions of reasoning on issues and in commit messages.
          Hide
          garydgregory Gary Gregory added a comment -

          Hello Jason Tedor:

          Say you have loggers built with Classes for which getName() give you:

          • com.example.app.A
          • com.example.app.A$AS1
          • com.example.app.A$AS2
          • ...
          • com.example.app.A$ASN

          Before 2.9.0: You you set the root logger to WARN and com.example.app.A to INFO, then you get INFO events for A but you do not get INFO messages from AS1, AS2, and so on. There is no way to set all A$ASx loggers to the same level at the same time.

          In 2.9.0 now, converting a Class to a logger name uses getCannonicalName() such that the logger names are:

          • com.example.app.A
          • com.example.app.A.AS1
          • com.example.app.A.AS2
          • ...
          • com.example.app.A.ASN

          When you set com.example.app.A to INFO, then you get INFO events for A, AS1, AS2, and so on.

          The dev ML thread is:

          https://lists.apache.org/thread.html/43b83474aad9c8625e5a6a63d2595c9d795dd6a51076493bacd87a36@%3Cdev.logging.apache.org%3E

          Gary

          Show
          garydgregory Gary Gregory added a comment - Hello Jason Tedor : Say you have loggers built with Classes for which getName() give you: com.example.app.A com.example.app.A$AS1 com.example.app.A$AS2 ... com.example.app.A$ASN Before 2.9.0: You you set the root logger to WARN and com.example.app.A to INFO , then you get INFO events for A but you do not get INFO messages from AS1 , AS2 , and so on. There is no way to set all A$ASx loggers to the same level at the same time. In 2.9.0 now, converting a Class to a logger name uses getCannonicalName() such that the logger names are: com.example.app.A com.example.app.A.AS1 com.example.app.A.AS2 ... com.example.app.A.ASN When you set com.example.app.A to INFO , then you get INFO events for A , AS1 , AS2 , and so on. The dev ML thread is: https://lists.apache.org/thread.html/43b83474aad9c8625e5a6a63d2595c9d795dd6a51076493bacd87a36@%3Cdev.logging.apache.org%3E Gary
          Hide
          jasontedor Jason Tedor added a comment -

          I understand the implications for nested classes, but it's specifically local and anonymous classes for which this change is problematic. For these classes, their canonical name is null. Previously logging levels for a logger for such a class could at least be controlled at say the package level and now instead even trying to get a logger by class name for such a logger will blow up (since its name is null). I read through the dev list and I do not see any discussion on this point.

          I start to wonder if maybe the right change here would have been to treat `$` also a hierarchical separator in addition to `.`, rather than changing which name is used?

          Show
          jasontedor Jason Tedor added a comment - I understand the implications for nested classes, but it's specifically local and anonymous classes for which this change is problematic. For these classes, their canonical name is null. Previously logging levels for a logger for such a class could at least be controlled at say the package level and now instead even trying to get a logger by class name for such a logger will blow up (since its name is null). I read through the dev list and I do not see any discussion on this point. I start to wonder if maybe the right change here would have been to treat `$` also a hierarchical separator in addition to `.`, rather than changing which name is used?
          Hide
          jasontedor Jason Tedor added a comment -

          Also, I want to thank you for your quick response and the link to the dev list, both are very helpful and appreciated.

          Show
          jasontedor Jason Tedor added a comment - Also, I want to thank you for your quick response and the link to the dev list, both are very helpful and appreciated.
          Hide
          garydgregory Gary Gregory added a comment -

          Using custom separators was discussed and rejected. The fix here will be to use getName() if getCannonicalName() returns null.

          Show
          garydgregory Gary Gregory added a comment - Using custom separators was discussed and rejected. The fix here will be to use getName() if getCannonicalName() returns null.
          Hide
          jasontedor Jason Tedor added a comment -

          That fix would be acceptable to me.

          Show
          jasontedor Jason Tedor added a comment - That fix would be acceptable to me.
          Hide
          garydgregory Gary Gregory added a comment -

          Reopening to adjust for a null cannonical name.

          Show
          garydgregory Gary Gregory added a comment - Reopening to adjust for a null cannonical name.
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit ae33698a1846a5e10684ec3e52a99223f06047af in logging-log4j2's branch refs/heads/master from Gary Gregory
          [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=ae33698 ]

          LOG4J2-2023 Use a class' canonical name instead of name to create its
          logger name. If the canonical name is null, then use the class name.

          Show
          jira-bot ASF subversion and git services added a comment - Commit ae33698a1846a5e10684ec3e52a99223f06047af in logging-log4j2's branch refs/heads/master from Gary Gregory [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=ae33698 ] LOG4J2-2023 Use a class' canonical name instead of name to create its logger name. If the canonical name is null, then use the class name.
          Hide
          garydgregory Gary Gregory added a comment -

          In git master. Please verify and close this issue.

          Show
          garydgregory Gary Gregory added a comment - In git master. Please verify and close this issue.
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit 3752f48e80600f40e5a31d62a2bbeeeca84cdbe2 in logging-log4j2's branch refs/heads/master from Gary Gregory
          [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=3752f48 ]

          LOG4J2-2023 Use a class' canonical name instead of name to create its
          logger name. Add tests.

          Show
          jira-bot ASF subversion and git services added a comment - Commit 3752f48e80600f40e5a31d62a2bbeeeca84cdbe2 in logging-log4j2's branch refs/heads/master from Gary Gregory [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=3752f48 ] LOG4J2-2023 Use a class' canonical name instead of name to create its logger name. Add tests.
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit 842d1d8ea1e8a94eead1ab0af3ade5c3b9c843ee in logging-log4j2's branch refs/heads/master from Gary Gregory
          [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=842d1d8 ]

          LOG4J2-2023 Use a class' canonical name instead of name to create its
          logger name. If the canonical name is null, then use the class name.

          Show
          jira-bot ASF subversion and git services added a comment - Commit 842d1d8ea1e8a94eead1ab0af3ade5c3b9c843ee in logging-log4j2's branch refs/heads/master from Gary Gregory [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=842d1d8 ] LOG4J2-2023 Use a class' canonical name instead of name to create its logger name. If the canonical name is null, then use the class name.
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit 9940e75f6ddbfa0950dad1e0b2479c0ef6ba1876 in logging-log4j2's branch refs/heads/master from Gary Gregory
          [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=9940e75 ]

          LOG4J2-2023 Use a class' canonical name instead of name to create its
          logger name. If the canonical name is null, then use the class name.

          Show
          jira-bot ASF subversion and git services added a comment - Commit 9940e75f6ddbfa0950dad1e0b2479c0ef6ba1876 in logging-log4j2's branch refs/heads/master from Gary Gregory [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=9940e75 ] LOG4J2-2023 Use a class' canonical name instead of name to create its logger name. If the canonical name is null, then use the class name.
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit e67bf824bd8e9a6d3c796c53a359c89f2fbdc4e1 in logging-log4j2's branch refs/heads/master from Gary Gregory
          [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=e67bf82 ]

          LOG4J2-2023 Use a class' canonical name instead of name to create its
          logger name. If the canonical name is null, then use the class name.
          More tests getLogger() vs. getLogger(Class).

          Show
          jira-bot ASF subversion and git services added a comment - Commit e67bf824bd8e9a6d3c796c53a359c89f2fbdc4e1 in logging-log4j2's branch refs/heads/master from Gary Gregory [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=e67bf82 ] LOG4J2-2023 Use a class' canonical name instead of name to create its logger name. If the canonical name is null, then use the class name. More tests getLogger() vs. getLogger(Class).
          Hide
          jasontedor Jason Tedor added a comment -

          The solution you have committed will work for me. It might be useful to add a comment explaining when the canonical name can be null.

          Again, thank you!

          Show
          jasontedor Jason Tedor added a comment - The solution you have committed will work for me. It might be useful to add a comment explaining when the canonical name can be null. Again, thank you!

            People

            • Assignee:
              garydgregory Gary Gregory
              Reporter:
              garydgregory Gary Gregory
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development