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 appears.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
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.
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.
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.
Also as it was mentioned you should also set the following. I forgot to mention this.
In log4j.properties you can define individual levels on a per logger basis:
In log4j.xml the syntax is
<name> is often the full qualified classname. You might want to use WARN or ERROR instead of FATAL
You can do it by changing logger level in log4j.properties/log4j.xml file.
You need to set logger's
<level value="off"/>
if you want to filter logs from package but keep logger configuration for later use. You could also set it to highest level to log only in case of error or fatal issue.Following entries should be added to log4j.xml to turn off logging from hibernate and springframework packages: