ops4j / org.ops4j.pax.logging

The OSGi Logging framework implementation. Supports SLF4J,LOG4J,JCL etc.
https://ops4j1.jira.com/wiki/spaces/paxlogging/overview
Apache License 2.0
46 stars 79 forks source link

[2.0.x] parameter with value {} is replaced with null #516

Closed rastislavpapp closed 1 year ago

rastislavpapp commented 1 year ago

environment - karaf 4.4.3, pax logging 2.2.0, using slf4j api and log4j2 implementation

problem:

log.info("ABC {} DEF", "test{}test");

outputs:

ABC testnulltest DEF
grgrzybek commented 1 year ago

Thanks for report - I'll check soon.

grgrzybek commented 1 year ago

Just a question - how did you obtain the log instance? what's the class of this instance?

rastislavpapp commented 1 year ago

log instance is obtained via

this.log = org.slf4j.LoggerFactory.getLogger(loggerName);

and it is an instance of org.ops4j.pax.logging.slf4j.Slf4jLogger

as I've investigated a little further, in the Slf4jLogger the message gets formatted correctly, via these calls:

 FormattingTuple tuple = MessageFormatter.arrayFormat(format, argArray);
m_delegate.debug(m, tuple.getMessage(), tuple.getThrowable());

after this, tuple.getMessage() returns "ABC test{}test DEF", but then it is formatted again in PaxLoggerImpl:

FormattingTriple ft = FormattingTriple.discover(format, false, arg);
doLog(marker.log4j2Marker(), Level.DEBUG, m_fqcn, ft.getMessage(), ft.getThrowable(), ft.getServiceReference(), ft.getArgArray());

After this, ft.getMessage() returns "ABC testnulltest DEF", I guess it took the {} as a place to put an exception (which is not present as a last argument, so it is null)

grgrzybek commented 1 year ago

@rastislavpapp I've fixed this issue in 2.2.x branch - thank you very much for spotting, because it wass quite serious bug.

If you need a release, just let me know ;)

cc: @jbonofre