Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-2970

Adding String return type of each log method

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Resolved
    • Critical
    • Resolution: Won't Do
    • 2.13.3
    • None
    • API
    • Important

    Description

      In many industry systems,  we need to log the error and then throw a new exception with the same message. The logger will populate the message with markers and variables.

      But we need to manually populated it by string + again when construct the exception message. This is an anti-pattern.

      Please take below snippet as example:

      log.error("The number of records is {} which exceed the threshold {}",  num, threshold); 
      throw new ValidationException("The number of record is " + num + " which exceed the threshold " + threshold);
      

       

      If the API can return populated message, the code would turn much better:

      String error = log.error("The number of records is {} which exceed the threshold {}",  num, threshold);
      throw new ValidationException(error);
      
      

       

      The only concern is that this may only works for synchronous logging, not work for asynchronous way. But I believe it could be resolved.

      Attachments

        Activity

          People

            Unassigned Unassigned
            berlou Colin Zhang
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 168h
                168h
                Remaining:
                Remaining Estimate - 168h
                168h
                Logged:
                Time Spent - Not Specified
                Not Specified