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

前端 未结 5 678
感情败类
感情败类 2020-11-28 05:21

Is there any advantage of using {} instead of string concatenation?

An example from slf4j

logger.debug(\"Temperature set to {}. Old temp         


        
5条回答
  •  难免孤独
    2020-11-28 05:53

    Another alternative is String.format(). We are using it in jcabi-log (static utility wrapper around slf4j).

    Logger.debug(this, "some variable = %s", value);
    

    It's much more maintainable and extendable. Besides, it's easy to translate.

提交回复
热议问题