Filtering out log4j messages from third-party frameworks?

后端 未结 4 537
粉色の甜心
粉色の甜心 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:41

    Just don't add those packages in your log4j.properties. For instance, you must have this for Spring in your properties file. Take it out if you have some entries like below (anything that starts with org.springframework). Same needs to be done for hibernate.

    #Logs the SQL from Spring
    log4j.logger.org.springframework.jdbc.core.JdbcTemplate=ERROR
    #Logs the SQL parameters from Spring
    log4j.logger.org.springframework.jdbc.core.StatementCreatorUtils=ERROR
    

    Also as it was mentioned you should also set the following. I forgot to mention this.

    log4j.rootLogger=FATAL  
    or   
    log4j.rootLogger=ERROR  
    

提交回复
热议问题