Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to display the following details in org.slf4j.Logger?

What is the best way to display the following details in org.slf4j.Logger

logger.info(problemCount + " problem entries deleted for the Object: " + id );

This is info, I want to display these finer details for a while to help with issues by looking at the logs.

I know there are some references that says built-in string formatting should be used instead of string concatenation like the following

logger.info(String.format("%d problem entries deleted for the Object: %s ",problemCount, id));

Is there an efficient way to write these kinds of log statements in java using org.slf4j.Logger?

Refer the link below as to why answer is preferred based on efficiency and performance.

Logger slf4j advantages of formatting with {} instead of string concatenation

like image 774
Madhu Tomy Avatar asked Dec 22 '25 01:12

Madhu Tomy


1 Answers

Yes, you can also do like this

logger.info( "{} problem entries deleted for the Object: {}",problemCount , id );
like image 90
Rahul Kumar Avatar answered Dec 23 '25 13:12

Rahul Kumar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!