Details
-
New Feature
-
Status: Resolved
-
Critical
-
Resolution: Won't Do
-
2.13.3
-
None
-
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.