logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Scott Deboy <scott.de...@gmail.com>
Subject Re: Filter log based on package when using getLogger(String)
Date Wed, 18 Jul 2012 17:55:12 GMT
Correction: expression would use the LOGGER instead of MSG, since you're
filtering on that.

On Wed, Jul 18, 2012 at 10:54 AM, Scott Deboy <scott.deboy@gmail.com> wrote:

> You can use filters, including the ExpressionFilter, to build pretty much
> arbitrary expressions and filter appenders using that, but it requires you
> to use a log4j.xml configuration file.
>
> Something like this (requires you to have the 'extras' companion in your
> classpath):
>
>                 <filter class="org.apache.log4j.filter.ExpressionFilter">
>                                 <param name="Expression" value="MSG ~=
> #3"/>
>                                 <param name="AcceptOnMatch"
> value="false"/>
>                         </filter>
> Scott
>
>
> On Wed, Jul 18, 2012 at 10:26 AM, Charles Hache <chache@tsco.ca> wrote:
>
>> Hello folks,
>>
>> Most of my loggers are constructed with the Logger.getLogger(String)
>> function, so that I can have loggers like "Device(#3, Some Description)"
>> instead of "ca.something.package.Device" with the goal of being able to
>> more easily identify which instances are writing what log lines.
>>
>> I've found that when I do this I can't use properties to filter the log
>> level, such as
>> log4j.logger.ca.something.**package=INFO
>> I figure this is because if I use getLogger(Device.class) it gets the
>> package of the logger from the class I give it and it all works from there.
>>
>> So this all makes sense, but brings up two questions:
>>
>> Can I still declare my loggers with a String name (getLogger(String)) and
>> somehow still use package-style log level selection in the properties file?
>>
>> If not, do you guys have any tips on how to differentiate between
>> instances when they're logging?  The obvious solution would be to prepend
>> any log message I want to write with a description of the instance, but
>> that seems like a lot of extra work.
>>
>> I think really what I'm looking for is something like getLogger(Class
>> theClass, String theName), but maybe there is an already-implemented way to
>> do this.
>>
>> Any tips?
>>
>> Regards,
>> Charles
>>
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: log4j-user-unsubscribe@**logging.apache.org<log4j-user-unsubscribe@logging.apache.org>
>> For additional commands, e-mail: log4j-user-help@logging.**apache.org<log4j-user-help@logging.apache.org>
>>
>>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message