Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. 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

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.6.2
    • Fix Version/s: 2.11.2
    • Component/s: API
    • Labels:

      Description

      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:

      TestingLogging.java
       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());
          }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                m8ypie Joel Berta
              • Votes:
                1 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: