I would say to increase performance by reducing String concatenations
.
When you write this
"Processing trade with id: " + id + " symbol: " + symbol
You are creating the printing string manually.
When you write
"Processing trade with id: {} and symbol : {} ", id, symbol
-------^id------------^symbol---------
In the second way before printing internally slf4j
maintaind and generate a new string again with concatenation (Haven't check the source code,may be a StringBuilder
).
The {}
called as place holders and replace by the args passed by you.
From docs of sl4j
This form avoids superfluous string concatenation when the logger is disabled for the DEBUG level. However, this variant incurs the hidden (and relatively small) cost of creating an Object[] before invoking the method, even if this logger is disabled for DEBUG. The variants taking one and two arguments exist solely in order to avoid this hidden cost.
Read how to use the format :How to use java.String.format in Scala?