Vertx 4 not getting log4j config

296 views
Skip to first unread message

Richard Gong

unread,
Mar 26, 2021, 2:46:11 PM3/26/21
to vert.x
I'm getting weird exception while logging messages in Vertx 4. Vertx4 does not have this issue. The code snippet is like this,

import io.vertx.core.impl.logging.Logger;
import io.vertx.core.impl.logging.LoggerFactory;
...
private final Logger logger = LoggerFactory.getLogger(this.getClass());
...
logger.info("I am here");

I have log4j2.xml in the class path as the following.

<?xml version="1.0" encoding="UTF-8"?>
<Configuration packages="com.roku">
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{ISO8601} | %t | %p | %c:%L | %vctx{traceId} | %m%n"/>
        </Console>
    </Appenders>
    <Loggers>
        <Root level="info">
            <AppenderRef ref="Console"/>
        </Root>
    </Loggers>
</Configuration>

Apparently the error output does NOT follow the pattern layout in the config file, meaning Vertx logging does not use the config at all. I tried out the instruction but still no luck. What else am I missing?

2021-03-26 11:19:33,006 vert.x-eventloop-thread-1 ERROR An exception occurred processing Appender Console java.util.NoSuchElementException: No value present
at java.base/java.util.Optional.get(Optional.java:148)
at org.apache.logging.log4j.util.StackLocator.calcLocation(StackLocator.java:79)
at org.apache.logging.log4j.util.StackLocatorUtil.calcLocation(StackLocatorUtil.java:71)
at org.apache.logging.log4j.core.impl.MutableLogEvent.getSource(MutableLogEvent.java:369)
at org.apache.logging.log4j.core.pattern.LineLocationPatternConverter.format(LineLocationPatternConverter.java:57)
at org.apache.logging.log4j.core.pattern.PatternFormatter.format(PatternFormatter.java:38)
at org.apache.logging.log4j.core.layout.PatternLayout$PatternSerializer.toSerializable(PatternLayout.java:334)
at org.apache.logging.log4j.core.layout.PatternLayout.toText(PatternLayout.java:233)
at org.apache.logging.log4j.core.layout.PatternLayout.encode(PatternLayout.java:218)
at org.apache.logging.log4j.core.layout.PatternLayout.encode(PatternLayout.java:58)
at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.directEncodeEvent(AbstractOutputStreamAppender.java:197)
at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.tryAppend(AbstractOutputStreamAppender.java:190)
at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.append(AbstractOutputStreamAppender.java:181)
at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:156)
at org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:129)
at org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:120)
at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:84)
at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:464)
at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:448)
at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:431)
at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:406)
at org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:63)
at org.apache.logging.log4j.core.Logger.logMessage(Logger.java:146)
at org.apache.logging.slf4j.Log4jLogger.log(Log4jLogger.java:376)
at io.vertx.core.logging.SLF4JLogDelegate.log(SLF4JLogDelegate.java:188)
at io.vertx.core.logging.SLF4JLogDelegate.log(SLF4JLogDelegate.java:160)
at io.vertx.core.logging.SLF4JLogDelegate.log(SLF4JLogDelegate.java:156)
at io.vertx.core.logging.SLF4JLogDelegate.info(SLF4JLogDelegate.java:104)

Richard Gong

unread,
Mar 26, 2021, 5:20:28 PM3/26/21
to vert.x
It ends up that it's bug of log4j 2.11.2 I used. The error went away after upgraded to 2.14.1

Thomas SEGISMONT

unread,
Mar 27, 2021, 6:15:33 AM3/27/21
to vert.x
Thanks for letting us know

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/7fcc81f9-8612-45c9-8315-50435a26a16fn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages