log4j performance

前端 未结 7 1685
终归单人心
终归单人心 2021-01-08 01:18

I\'m developing a web app, and I\'d like to log some information to help me improve and observe the app. (I\'m using Tomcat6)

First I thought I would use StringBuild

相关标签:
7条回答
  • 2021-01-08 02:02

    If performance is really a concern have a look for slf4j: http://www.slf4j.org/manual.html

    With their placeholder approach they are faster than log4j when you disabled logging those messages, because in log4j the string concatenation takes places independently the message is really needed. Slf4j only replaces the placeholder if this message will be really logged.

    But you can do something like this in log4j:

    if(l.isDebugEnabled()) l.debug("log entry: " + 7);
    

    But i think it's a lot of boilerplate-code so i am using slf4j

    0 讨论(0)
提交回复
热议问题