Rakesh Juyal
Rakesh Juyal

Reputation: 36799

How to disable the debug logging of class using log4j?

In my log4j.xml, i am having

<logger name="java.sql">
   <level value="DEBUG" />
</logger>

But using this, it also enables the logging for the interface Resultset. If i want to disable the logging for this interface but still want to have the debug logging for statement, preparedstatement, etc... How can i do this?

Upvotes: 2

Views: 6674

Answers (2)

Stephen C
Stephen C

Reputation: 719596

Log4j does not allow you to control logging based on class or package names per se. Rather, the granularity of logging control with log4j (and similar Java loggers) is determined by the logger names used by the application. If your JDBC driver has different loggers for statements, prepared statements, resultsets and so on, you are fine. However, if it uses a single logger for all of its logging, you would need to resort to some kind of filtering.

For more information, this page has a section on configuring filters in an XML Configuration file, and the Filter javadoc lists the available (standard) filter classes. For example, you can filter based on whether a logging event's message matches a given string.

Having said that, the filtering approach will be cumbersome, especially if there are lots of different messages to be filtered in / out.

Upvotes: 2

Yoni
Yoni

Reputation: 10321

You can use individual loggers for each of those classes or packages, but it depends how those classes created there own loggers.

Although, you are better of focusing on the vendor's implementation of those classes instead of focusing on the interfaces.

Upvotes: 0

Related Questions