Reputation: 2041
There is some auditing in my application. Every audit event has it's own log4j category with name that is prefixed by same string.
EG: general auditing category name: com.company.audit
web login category name: com.company.audit.web.login
create something: com.company.audit.api.create
etc..
some of the categories should be logged by default, but some not =>
<category name="com.compamy.audit" additivity="true">
<priority value="INFO"/>
</category>
<category name="com.company.audit.web.login" additivity="true">
<priority value="DEBUG">
</category>
As default is INFO second category shouldn't be logged. At least I thought it but it doesn't work. Any help how to override logging level on 'sub-category'.
NOTE: I don't have much possibility to change a naming scheme as a whole
ADDED:
here is configuration of appender:
<appender class="org.apache.log4j.RollingFileAppender" name="Company_AUDIT">
<param name="File" value="${jboss.server.log.dir}/company_audit.log"/>
<param value="10000KB" name="MaxFileSize"/>
<param value="10" name="MaxBackupIndex"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="foo"/>
</layout>
</appender>
Upvotes: 0
Views: 2920
Reputation: 1232
Your configuration means: for category com.company.audit
, log all messages of level INFO
or higher. For com.company.audit.web.login
, log all messages of level DEBUG
or higher. So all the messages of the second category are logged, which is what you asked for.
What you really want is to select whether the second category is displayed or not. I can think of two approaches to do that:
in your code, use the convention that all messages in com.company.audit
will be logged at level INFO
, and all messages in com.company.audit.web.login
will be logged at level DEBUG
. In your configuration, you only need to set the level of the main category:
DEBUG
: display all messagesINFO
: don't display "optional" messages (i.e. those of the subcategory)In the configuration, put com.company.audit.web.login
to level OFF
when you want to disable its messages. When you want to activate it, just comment the line (it will inherit the configuration from the main category).
I prefer the second option, because you can keep using the level for message gravity (what it is originally meant for).
Upvotes: 1