Stefan Küttner created LOG4J2-2531:
--------------------------------------
Summary: 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.11.1, 2.10.0, 2.9.1
Reporter: Stefan Küttner
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
(v7.6.3#76005)