flapdoodle-oss / de.flapdoodle.embed.mongo

...will provide a platform neutral way for running mongodb in unittests.
Apache License 2.0
908 stars 160 forks source link

Log formatting issue when message contains "{}" #514

Closed kilink closed 6 months ago

kilink commented 7 months ago

If a message that contains "{}" is logged, an exception gets thrown:

2024-04-05T18:27:52.391240Z Thread-10 ERROR Unable to format msg: {"t":{"$date":"2024-04-05T11:27:52.390-07:00"},"s":"I",  "c":"STORAGE",  "id":20320,   "ctx":"conn3","msg":"createCollection","attr":{"namespace":"test.metadata","uuidDisposition":"generated","uuid":{"uuid":{"$uuid":"12d30956-5128-47d8-8d3b-1c342f39b9a2"}},"options":{}}} java.lang.IllegalArgumentException: found 1 argument placeholders, but provided 0 for pattern `{"t":{"$date":"2024-04-05T11:27:52.390-07:00"},"s":"I",  "c":"STORAGE",  "id":20320,   "ctx":"conn3","msg":"createCollection","attr":{"namespace":"test.metadata","uuidDisposition":"generated","uuid":{"uuid":{"$uuid":"12d30956-5128-47d8-8d3b-1c342f39b9a2"}},"options":{}}}`
    at org.apache.logging.log4j.message.ParameterFormatter.formatMessage(ParameterFormatter.java:248)
    at org.apache.logging.log4j.message.ParameterizedMessage.formatTo(ParameterizedMessage.java:282)
    at org.apache.logging.log4j.core.pattern.MessagePatternConverter$SimpleMessagePatternConverter.format(MessagePatternConverter.java:120)
    at org.apache.logging.log4j.core.layout.PatternLayout$NoFormatPatternSerializer.toSerializable(PatternLayout.java:355)
    at org.apache.logging.log4j.core.layout.PatternLayout.toText(PatternLayout.java:252)
    at org.apache.logging.log4j.core.layout.PatternLayout.encode(PatternLayout.java:238)
    at org.apache.logging.log4j.core.layout.PatternLayout.encode(PatternLayout.java:58)
    at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.directEncodeEvent(AbstractOutputStreamAppender.java:227)
    at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.tryAppend(AbstractOutputStreamAppender.java:220)
    at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.append(AbstractOutputStreamAppender.java:211)
    at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:160)
    at org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:133)
    at org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:124)
    at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:88)
    at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:705)
    at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:663)
    at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:639)
    at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:575)
    at org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:92)
    at org.apache.logging.log4j.core.Logger.log(Logger.java:169)
    at org.apache.logging.log4j.spi.AbstractLogger.tryLogMessage(AbstractLogger.java:2906)
    at org.apache.logging.log4j.spi.AbstractLogger.logMessageTrackRecursion(AbstractLogger.java:2859)
    at org.apache.logging.log4j.spi.AbstractLogger.logMessageSafely(AbstractLogger.java:2841)
    at org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:2631)
    at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:2394)
    at org.apache.logging.slf4j.Log4jLogger.info(Log4jLogger.java:188)
    at de.flapdoodle.embed.process.io.Slf4jLevel$3.log(Slf4jLevel.java:42)
    at de.flapdoodle.embed.process.io.Slf4jStreamProcessor.process(Slf4jStreamProcessor.java:40)

This is due to the way SLF4J is called in Slf4jStreamProcessor.process:

public void process(String line) {
    level.log(logger, stripLineEndings(line));
}

Instead of passing line in as the message, it should probably use a placeholder:

public void process(String line) {
    level.log(logger, "{}", stripLineEndings(line));
}
michaelmosmann commented 7 months ago

@kilink .. ah.. but only if log4j is the backend.. hmm..

michaelmosmann commented 7 months ago

@kilink .. will make an release soon. fixed that..

michaelmosmann commented 6 months ago

@kilink release done.. this should be solved.. 4.13.0:)