[ 
https://issues.apache.org/jira/browse/LOG4J2-1570?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16742730#comment-16742730
 ] 

Ralph Goers commented on LOG4J2-1570:
-------------------------------------

I have a fix. It seems the iostreams module fails when stack walking is done 
from the top down. I don't know why we don't normally see it but it also fails 
in Java 11 when using StackWalker. The problem is that the iostream loggers are 
called by the application and then delegate to Java I/O classes which 
eventually end up calling the same iostream class. So it ends up locating a sun 
class instead of the caller. I am considering ways to deal with this.

> 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
> --------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: LOG4J2-1570
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1570
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: API
>    Affects Versions: 2.6.2
>            Reporter: Joel Berta
>            Priority: Minor
>              Labels: easyfix, newbie
>
> While logging a message using lambda expressions. If i call a method within 
> the log message (i.e logger.info(() -> "foo" +bar()) which also logs 
> messages, those logs within the called method will reference the line number 
> and method name of the method which invoked it.
> Running the following code demonstrates this issue:
> {code:title=TestingLogging.java|borderStyle=solid}
>  private static final Logger LOGGER = 
> LogManager.getLogger(TestingLogging.class);
>     public static String foo(){
>         LOGGER.info("bar");
>         return "foo";
>     }
>     public static void main(String[] args){
>         System.out.println("correct method reference: ");
>         LOGGER.info(foo());
>         System.out.println("\nincorrect method reference: ");
>         // causes logging in foo to reference
>         // this line number and method (main)
>         LOGGER.info(() -> foo());
>     }
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to