chibenwa commented on code in PR #2386:
URL: https://github.com/apache/james-project/pull/2386#discussion_r1726620585
##########
protocols/imap/src/main/java/org/apache/james/imap/message/response/ImmutableStatusResponse.java:
##########
@@ -72,12 +70,22 @@ public ImapCommand getCommand() {
@Override
public String toString() {
- return MoreObjects.toStringHelper(this)
- .add("responseCode", responseCode)
- .add("serverResponseType", serverResponseType)
- .add("tag", tag)
- .add("textKey", textKey)
- .add("command", command)
- .toString();
+ final StringBuilder sb = new StringBuilder();
+ if (getResponseCode() != null) {
+ sb.append(' ').append(getResponseCode());
+ }
+ if (getServerResponseType() != null) {
+ sb.append(' ').append(getServerResponseType());
+ }
+ if (getTag() != null) {
+ sb.append(' ').append(getTag());
+ }
+ if (getTextKey() != null) {
+ sb.append(' ').append(getTextKey());
+ }
+ if (getCommand() != null) {
+ sb.append(' ').append(getCommand());
+ }
+ return sb.toString();
Review Comment:
> should we use asString() for custom string output?
+1
> which (in case of logging) may require additional guards for log-levels?
That's true!
In non critical code portions or non costly operations we don't really care
but for big string concatenations this might be a concern.
I'm sorry to be peacky, this kind of stuff in IMAP code tend to have a non
neglictible impact on CPU (mdc context handling) and memory allocations in what
I could see with flame graphs (cf async-profiler) and being careful here do not
cost much.
If wrapping things in ifs is for you also not your cup of tea we apparently
can use suppliers in the logging event builder (I just found this out!)
```
LOGGER.makeLoggingEventBuilder(Level.DEBUG)
.setMessage("My message: {}")
.addArgument(() -> "I'm costly and I know it!")
.log();
```
And under the hood (log4j but other log provider would do the same):
```
logBuilder.log(this.message, this.arguments.toArray());
```
Could be nice to defer expensive argument evaluation, eg for custom displays?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]