[
https://issues.apache.org/jira/browse/LOG4J2-2531?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Ralph Goers resolved LOG4J2-2531.
---------------------------------
Resolution: Won't Fix
This is behaving correctly. The call to the Logging API is made from the
ifPresent method. There is no way Log4j can know it is called from a Lambda
expression.
> Using method references to Logger methods leads to wrong source file and line
> number in log entry
> -------------------------------------------------------------------------------------------------
>
> Key: LOG4J2-2531
> URL: https://issues.apache.org/jira/browse/LOG4J2-2531
> Project: Log4j 2
> Issue Type: Bug
> Affects Versions: 2.9.1, 2.10.0, 2.11.1
> Reporter: Stefan Küttner
> Priority: Major
> Labels: Java8, Lambda, java.util.Optional
>
> The following example produces a log message with origin
> {{Optional.ifPresent}} which is wrong.
> {code:java}
> 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());
> }
> }
> {code}
> This may or may not be related to LOG4J2-1570.
--
This message was sent by Atlassian Jira
(v8.20.1#820001)