I am working with an external package which uses a log4j quite verbosely. I've looked at the code and found the expected log4j
lines:
private Logger log = Logger.getLogger("SomeLoggerName");
...
log.info("Trivial message");
log.info("More trivial data");
Since I can't change the code, I've tried to change log4j.xml
:
<category name="SomeLoggerName">
<level value="${log4j_level:-WARN}"/>
<appender-ref ref="FileLogger"/>
</category>
I guessed thatcategory name
property is equivalent to the logger name. Is it true? If not, how can I filter by logger name?
If you're just looking to turn down verbosity, I'd just turn up the priority level:
Otherwise, you might want to add a filter to your existing appender. First, implement a log4j filter. In your case it would be a simple comparison to determine whether or not the log event was from the unwanted class. Something like this would work:
Once you have your filter implemented, just add it to your log4j appender like so:
If you need more control, the filter will be able to give you extremely fine-grained control over your logging.
Actually, you can use
<logger>
as an element name, e.g.I think
category
is there for backward compatibility and its use is deprecated.You are right, logger == category. Do you have problems with your configuration? Generally it looks OK and should work.