You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Colin Zhang (Jira)" <ji...@apache.org> on 2020/12/04 04:51:00 UTC
[jira] [Updated] (LOG4J2-2970) Adding String return type of each
log method
[ https://issues.apache.org/jira/browse/LOG4J2-2970?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Colin Zhang updated LOG4J2-2970:
--------------------------------
Description:
In many industry system, we need to log the error in the log 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 again by string + again when construct the exception message. This is an anti-pattern.
Please take below snippet as example:
{code:java}
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);
{code}
This is really bad since all the logging API are void.
If the API can return populated message, the code would turn into this:
{code:java}
String error = log.error("The number of records is {} which exceed the threshold {}", num, threshold);
throw new ValidationException(error);
{code}
was:
In many industry system, we need to log the error in the log 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 again by string + again when construct the exception message. This is an anti-pattern.
Please take below snippet as example:
{quote}
{code:java}
// code placeholder
{code}
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);
{quote}
This is really bad since all the logging API are void.
If the API can return populated message, the code would turn into this:
{quote}
{code:java}
// code placeholder
{code}
String error = log.error("The number of records is {} which exceed the threshold {}", num, threshold);
throw new ValidationException(error);
{quote}
> Adding String return type of each log method
> --------------------------------------------
>
> Key: LOG4J2-2970
> URL: https://issues.apache.org/jira/browse/LOG4J2-2970
> Project: Log4j 2
> Issue Type: New Feature
> Components: API
> Affects Versions: 2.13.3
> Reporter: Colin Zhang
> Priority: Critical
> Labels: API, user-experience
> Original Estimate: 168h
> Remaining Estimate: 168h
>
> In many industry system, we need to log the error in the log 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 again by string + again when construct the exception message. This is an anti-pattern.
> Please take below snippet as example:
> {code:java}
> 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);
> {code}
> This is really bad since all the logging API are void.
> If the API can return populated message, the code would turn into this:
> {code:java}
> String error = log.error("The number of records is {} which exceed the threshold {}", num, threshold);
> throw new ValidationException(error);
> {code}
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)