Filtering out log4j messages from third-party frameworks?

后端 未结 4 539
粉色の甜心
粉色の甜心 2020-12-04 18:14

How do I filter log messages from external third party frameworks? I am using Hibernate and Spring framework and I would like to suppress the logs so that only my log4j logs

4条回答
  •  感动是毒
    2020-12-04 18:47

    In my log4j.properties file I set the root logger logging level to ERROR. Then for packages I specifically want to log, like my application code, I set the logging level to INFO or DEBUG.

    log4j.rootLogger=ERROR, stdout
    log4j.logger.com.initech.tps=DEBUG
    log4j.logger.org.hibernate.SQL=INFO
    

    I see co-workers who set root logging low and then end up listing everything they don't want to see, that just seems backward to me. I would rather list what I want to log than all the things I don't want to log.

    BTW turning logging off entirely for a third-party component seems like a bad idea to me. For instance, Spring is relatively noisy and uses WARN for things I really don't need to know about, but if it logs an ERROR entry for something I want to see it.

提交回复
热议问题