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

Adding String return type of each log method

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

    Details

    • Type: New Feature
    • Status: Resolved
    • Priority: Critical
    • Resolution: Won't Do
    • Affects Version/s: 2.13.3
    • Fix Version/s: None
    • Component/s: API
    • Flags:
      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

            • Assignee:
              Unassigned
              Reporter:
              berlou Colin Zhang

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

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

                  Issue deployment