You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "ppkarwasz (via GitHub)" <gi...@apache.org> on 2023/02/02 20:35:36 UTC
[GitHub] [logging-log4j2] ppkarwasz opened a new issue, #1262: Detect suppliers passed as `Object` parameters
ppkarwasz opened a new issue, #1262:
URL: https://github.com/apache/logging-log4j2/issues/1262
## Description
While logger methods with `Supplier<?>` in the signature are the easiest way to log lazily, we should also detect when users pass suppliers as `Object` parameters. It would be nice if:
```lang-java
log.info("The {} {} {} jumps over the {}.", brown, quick, fox, (Supplier<?>) () -> "lazy dog");
```
gave the same result as:
```lang-java
log.info("The {} {} {} jumps over the {}.", () -> brown, () -> quick, () ->fox, () -> "lazy dog");
```
## References
This proble appears in a [StackOverflow question](https://stackoverflow.com/q/75326876/11748454), but probably in many more.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Detect suppliers passed as `Object` parameters (logging-log4j2)
Posted by "ppkarwasz (via GitHub)" <gi...@apache.org>.
ppkarwasz commented on issue #1262:
URL: https://github.com/apache/logging-log4j2/issues/1262#issuecomment-1698008178
I have to agree, I initially thought that we can call `Supplier#get()` on each parameter that implements `Supplier`. However in doing so we prevent users from logging objects that accidentally also implement `Supplier`, e.g. a factory might implement `Supplier`, but the user might want to log the factory's name instead.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [logging-log4j2] rgoers commented on issue #1262: Detect suppliers passed as `Object` parameters
Posted by "rgoers (via GitHub)" <gi...@apache.org>.
rgoers commented on issue #1262:
URL: https://github.com/apache/logging-log4j2/issues/1262#issuecomment-1434910554
I do not believe this is practically solvable using the standard API. However, I propose we enhance the LogBuilder to support this so you would code:
```
log.atInfo().withArg(() -> quick).withArg(() -> brown).withArg("fox").withArg(() -> "lazy dog").log("The {} {} {} jumps over the {}.");
```
We could also do
```
log.atInfo().withMsg("The {} {} {} jumps over the {}.").withArg(() -> quick).withArg(() -> brown).withArg("fox").withArg(() -> "lazy dog").log();
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Detect suppliers passed as `Object` parameters (logging-log4j2)
Posted by "ppkarwasz (via GitHub)" <gi...@apache.org>.
ppkarwasz closed issue #1262: Detect suppliers passed as `Object` parameters
URL: https://github.com/apache/logging-log4j2/issues/1262
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org