Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Won't Fix
-
2.9.1, 2.10.0, 2.11.1
-
None
-
None
Description
The following example produces a log message with origin Optional.ifPresent which is wrong.
package com.exxeta.log4j.test; import java.util.Optional; import java.util.function.Consumer; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.core.appender.ConsoleAppender; import org.apache.logging.log4j.core.config.Configurator; import org.apache.logging.log4j.core.config.builder.api.AppenderComponentBuilder; import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder; import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory; import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration; public class Log4jThreadAnalyzerErrorDemo { private static final Logger LOG; static { configureRootLogger(); LOG = LogManager.getRootLogger(); } public static void main(String[] args) { // This produces "INFO main - (Optional.java:159) - Optional.ifPresent: Hello World!" Optional.of("Hello World!").ifPresent(LOG::info); } private static void configureRootLogger() { ConfigurationBuilder<BuiltConfiguration> builder = ConfigurationBuilderFactory .newConfigurationBuilder(); AppenderComponentBuilder console = builder.newAppender("Stdout", "CONSOLE").addAttribute("target", ConsoleAppender.Target.SYSTEM_OUT); console.add(builder.newLayout("PatternLayout").addAttribute("pattern", "%n%d{dd.MM.yyyy HH:mm:ss} %-5p %t - (%F:%L) - %C{1}.%M: %m%n")); builder.add(console); builder.add(builder.newRootLogger(Level.INFO).add(builder.newAppenderRef("Stdout"))); Configurator.initialize(builder.build()); } }
This may or may not be related to LOG4J2-1570.
Attachments
Issue Links
- is related to
-
LOG4J2-1570 Logging with a lambda expression with a method call that also logs causes logs within method call to reference line num and method name as parent method
- Resolved