qos-ch / slf4j

Simple Logging Facade for Java
http://www.slf4j.org
MIT License
2.35k stars 990 forks source link

Platform Logging bridge should use MessageFormat but it's using String.format #273

Closed miyakawataku closed 1 year ago

miyakawataku commented 2 years ago

java.lang.System.Logger.log is specified to accept the message format of MessageFormat. However, the current SLF4JPlatformLogger implementation uses String.format instead of MessageFormat. As a result, the current implementation cannot format the message correctly.

Expected and actual behavior

LoggerFinder finder = System.LoggerFinder.getLoggerFinder();
Logger systemLogger = finder.getLogger("smoke", null);
systemLogger.log(Level.INFO, "hello {0}", "world");

Expected output:

INFO smoke - hello world

Actual output:

INFO smoke - hello {0}

What this change does

This change replaces use of String.format by MessageFormat.format to comply the spec of Platform Logging.

miyakawataku commented 2 years ago

Filed JIRA ticket SLF4J-529.

ben-manes commented 1 year ago

I ran into this @ceki and had to switch to formatting prior to logging. Please consider fixing this mistake.

rob-bygrave commented 1 year ago

Just checking to see if this PR is not yet merged for a reason or just busy?

SentryMan commented 1 year ago

I wonder about this one as well. It's a little inconvenient to deal with at the moment.