Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Core
    • Labels:
      None

      Description

      The fully qualified class name must be set correctly to support conversions like %C. In some cases, %C information is incorrect. I think this is related to AbstractLogger allowing getFQCN() to be overridden. Log methods handled by AbstractLogger should have AbstractLogger's FQCN, not that of the subclass.

      Example:

      slf4jLogger.info("slf4jLogger test %C."); // works; SLF4JLogger overrides this method
      slf4jLogger.info("slf4jLogger test %C.", t); // fails with '?'; handled by AbstractLogger
      category2.info("category test %C"); // fails with 'o.a.l.Category'

      Output:

      INFO Log4j2Testing [main] slf4jLogger test %C.
      INFO ? [main] slf4jLogger test %C.
      java.lang.Throwable
      at Log4j2Testing.main(Log4j2Testing.java:22)
      INFO o.a.l.Category [main] category test %C

        Activity

        John Vasileff created issue -
        Hide
        Ralph Goers added a comment -

        The category problems for the SLF4J api have been corrected. This probably also corrects the problem with log4j-over-slf4j, which is what I assume you meant by category2. However, it would be more appropriate to use the log4j12-api component of Log4j 2.0 if Log4j 2.0 is the underlying implementation.

        Show
        Ralph Goers added a comment - The category problems for the SLF4J api have been corrected. This probably also corrects the problem with log4j-over-slf4j, which is what I assume you meant by category2. However, it would be more appropriate to use the log4j12-api component of Log4j 2.0 if Log4j 2.0 is the underlying implementation.
        Ralph Goers made changes -
        Field Original Value New Value
        Status Open [ 1 ] Resolved [ 5 ]
        Assignee Ralph Goers [ ralph.goers@dslextreme.com ]
        Resolution Fixed [ 1 ]
        Hide
        John Vasileff added a comment -

        Actually, in the original report I was using log4j12-api. It was a puzzle to determine why your test passed while mine failed. My code looked like:

        import org.apache.log4j.Category;

        private static final org.apache.logging.log4j.Logger log4j2Logger = LogManager.getLogger(Log4j2Testing.class.getName());
        private static final Category category2 = Category.getInstance(Log4j2Testing.class);

        ...

        As it turns out, the order in which the loggers were created changed the result. See LOG4J2-51. I was able to get correct results by flipping the order of the getLogger/getInstance calls.

        In your patch for the SLF4J API, the problems with slf4jLogger are resolved since SLF4JLogger no longer extends AbstractLogger. But a problem remains with the getFQCN() logic.

        I have a patch to correct this. It builds on the patches in LOG4J2-51. Note: LOG4J2-51 temporarily causes your new test case to fail, but the forthcoming patch fixes the root cause.

        Show
        John Vasileff added a comment - Actually, in the original report I was using log4j12-api. It was a puzzle to determine why your test passed while mine failed. My code looked like: import org.apache.log4j.Category; private static final org.apache.logging.log4j.Logger log4j2Logger = LogManager.getLogger(Log4j2Testing.class.getName()); private static final Category category2 = Category.getInstance(Log4j2Testing.class); ... As it turns out, the order in which the loggers were created changed the result. See LOG4J2-51 . I was able to get correct results by flipping the order of the getLogger/getInstance calls. In your patch for the SLF4J API, the problems with slf4jLogger are resolved since SLF4JLogger no longer extends AbstractLogger. But a problem remains with the getFQCN() logic. I have a patch to correct this. It builds on the patches in LOG4J2-51 . Note: LOG4J2-51 temporarily causes your new test case to fail, but the forthcoming patch fixes the root cause.
        John Vasileff made changes -
        Resolution Fixed [ 1 ]
        Status Resolved [ 5 ] Reopened [ 4 ]
        Hide
        John Vasileff added a comment -

        Comments for 0004.patch

        cleanup FQCN code

        Make sure all application facing log methods use their own FQCN. This patch
        resolves a unit test failure for the %C pattern when using the Category logger.

        The AbstractLogger method:

        String getFQCN()

        was removed. Previously, subclasses were able to override this method which
        caused incorrect location data when AbstractLogger log methods were called
        directly by application code (i.e. not overridden by the subclass).

        Subclasses of AbstractLoggerWrapper that introduce their own log methods should call:

        log(Marker marker, String fqcn, Level level, Message data, Throwable t);

        where fqcn is Subclass.getName();

        Show
        John Vasileff added a comment - Comments for 0004.patch cleanup FQCN code Make sure all application facing log methods use their own FQCN. This patch resolves a unit test failure for the %C pattern when using the Category logger. The AbstractLogger method: String getFQCN() was removed. Previously, subclasses were able to override this method which caused incorrect location data when AbstractLogger log methods were called directly by application code (i.e. not overridden by the subclass). Subclasses of AbstractLoggerWrapper that introduce their own log methods should call: log(Marker marker, String fqcn, Level level, Message data, Throwable t); where fqcn is Subclass.getName();
        John Vasileff made changes -
        Attachment 0004-cleanup-FQCN-code.patch [ 12495003 ]
        Hide
        Ralph Goers added a comment -

        Patch applied. Please verify and close.

        Show
        Ralph Goers added a comment - Patch applied. Please verify and close.
        Ralph Goers made changes -
        Status Reopened [ 4 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        John Vasileff made changes -
        Status Resolved [ 5 ] Closed [ 6 ]

          People

          • Assignee:
            Ralph Goers
            Reporter:
            John Vasileff
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development