Log4j 2
  1. Log4j 2
  2. LOG4J2-49

double message formatting w/SLF4JLogger

    Details

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

      Description

      SLF4JLogger implements LocationAwareLogger which has

      public void log(Marker marker, String fqcn, int level, String message, Object[] argArray, Throwable t);

      Callers of this method format the message in advance. But SLF4JLogger also performs formatting.

      Example:

      slf4jLogger.info("slf4jLogger {}", "is formated twice? <{}>"); // works
      slf4jXlogger.info("slf4jXLogger {}", "is formated twice? <{}>"); // fails

      log4j2Logger.info("log4j2Logger shouldn't format <{}>"); // works
      jclOverSlf4jLogger.info("jclOverSlf4jLogger shouldn't format <{}>"); // fails

      Output:

      INFO Log4j2Testing [main] slf4jLogger is formated twice? <{}>
      INFO Log4j2Testing [main] slf4jXLogger is formated twice? <[[is formated twice? <{}>], null]>
      INFO Log4j2Testing [main] log4j2Logger shouldn't format <{}>
      INFO Log4j2Testing [main] jclOverSlf4jLogger shouldn't format <[null, null]>

        Activity

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

        This really should have been opened as two separate Jira issues.

        You have identified two problems:
        1. SLF4J's XLogger formats twice when one of the parameters contains "{}". I tested this with Logback (which I would consider to be the reference implementation for SLF4J) and it behaves more or less the same way. There was an issue regarding the "[" and "]" being inserted but after fixing the second item below the same output as Logback is logged.
        2. SLF4J's jcl-over-sl4j is formatting incorrectly. I have corrected this.

        Show
        Ralph Goers added a comment - This really should have been opened as two separate Jira issues. You have identified two problems: 1. SLF4J's XLogger formats twice when one of the parameters contains "{}". I tested this with Logback (which I would consider to be the reference implementation for SLF4J) and it behaves more or less the same way. There was an issue regarding the " [" and "] " being inserted but after fixing the second item below the same output as Logback is logged. 2. SLF4J's jcl-over-sl4j is formatting incorrectly. I have corrected this.
        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
        Ralph Goers added a comment -

        I should also point out that rather than using SLF4J's jcl-over-slf4j using log4j2-jcl would be more appropriate if the underlying implementation is Log4j 2.0.

        Show
        Ralph Goers added a comment - I should also point out that rather than using SLF4J's jcl-over-slf4j using log4j2-jcl would be more appropriate if the underlying implementation is Log4j 2.0.
        Hide
        Ralph Goers added a comment -

        Closing since there have not been any updates to this issue since it was marked resolved.

        Show
        Ralph Goers added a comment - Closing since there have not been any updates to this issue since it was marked resolved.
        Ralph Goers made changes -
        Status Resolved [ 5 ] Closed [ 6 ]

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development