You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Enric Jaen <en...@yahoo.es.INVALID> on 2017/11/23 12:14:56 UTC

new feature proposal - microloggers

Hi, Sometimes it happens that we want to see logs from a class, but not all logs as it can be verbose. I think it would useful to be able to filter logs inside a logger, specially when the logger is class.

For example we could use include and exclude regexps:


        <logger name=" org.springframework.beans.factory.support.DefaultListableBeanFactory" level="DEBUG">            <include string= "Creating shared instance of singleton bean"            <AppenderRef ref="PROJECT" />
        </logger>

or
        <logger name=" org.springframework.beans.factory.support.DefaultListableBeanFactory" level="DEBUG">            <exclude string= "Returning cached instance"
            <AppenderRef ref="PROJECT" />
        </logger>
        
What do you think?Regards
Enric

Re: new feature proposal - microloggers

Posted by Ralph Goers <ra...@dslextreme.com>.
This is a case where I would recommend the application be modified, if possible, to use a Marker. Instead of using a RegEx filter as Matt shows, which can be expensive if you have lots of logging, you could use the MarkerFilter. To do this, everywhere you log “Creating shared instance of singleton bean” or something else you would like to optionally suppress create a Marker and add it as a filter:

public static final Marker VERBOSE = MarkerManager.getMarker(“VERBOSE”);


logger.debug(VERBOSE, “Creating shared instance of singleton bean {}”, className);


<Logger name=“com.example.thing” level=“DEBUG”>
    <MarkerFilter marker=“VERBOSE” onMatch=“DENy” onMismatch=“NEUTRAL”/>
</Logger>

The usage of the filter is exactly as Matt explained regardless of which filter you use.

Ralph

> On Nov 24, 2017, at 10:27 AM, Matt Sicker <bo...@gmail.com> wrote:
> 
> On 23 November 2017 at 06:37, Remko Popma <re...@gmail.com> wrote:
> 
>> If you use a RegexFilter (
>> https://logging.apache.org/log4j/2.x/manual/filters.html#RegexFilter)
>> would
>> that meet your requirements?
>> 
>>>        <logger name=" org.springframework.beans.factory.support.
>> DefaultListableBeanFactory"
>>> level="DEBUG">            <include string= "Creating shared instance of
>>> singleton bean"            <AppenderRef ref="PROJECT" />
>>>        </logger>
>> 
> 
> Example usage:
> 
> <Logger name="com.example.thing" level="DEBUG">
>  <RegexFilter regex="Creating shared instance of singleton bean"
> onMismatch="DENY"/>
>  <AppenderRef ref="PROJECT"/>
> </Logger>
> 
> You can set that filter at the global level (inside <Configuration/>),
> per-appender (inside the <FooAppender/> element), per-logger (as
> described), or even inside the <AppenderRef/> element which can be useful
> if your <Logger/> has multiple AppenderRefs. See more info here: <
> https://logging.apache.org/log4j/2.x/manual/configuration.html#Filters>
> 
> -- 
> Matt Sicker <bo...@gmail.com>



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: new feature proposal - microloggers

Posted by Matt Sicker <bo...@gmail.com>.
On 23 November 2017 at 06:37, Remko Popma <re...@gmail.com> wrote:

> If you use a RegexFilter (
> https://logging.apache.org/log4j/2.x/manual/filters.html#RegexFilter)
> would
> that meet your requirements?
>
> >         <logger name=" org.springframework.beans.factory.support.
> DefaultListableBeanFactory"
> > level="DEBUG">            <include string= "Creating shared instance of
> > singleton bean"            <AppenderRef ref="PROJECT" />
> >         </logger>
>

Example usage:

<Logger name="com.example.thing" level="DEBUG">
  <RegexFilter regex="Creating shared instance of singleton bean"
onMismatch="DENY"/>
  <AppenderRef ref="PROJECT"/>
</Logger>

You can set that filter at the global level (inside <Configuration/>),
per-appender (inside the <FooAppender/> element), per-logger (as
described), or even inside the <AppenderRef/> element which can be useful
if your <Logger/> has multiple AppenderRefs. See more info here: <
https://logging.apache.org/log4j/2.x/manual/configuration.html#Filters>

-- 
Matt Sicker <bo...@gmail.com>

Re: new feature proposal - microloggers

Posted by Remko Popma <re...@gmail.com>.
Cool! Stay in touch: ideas are always welcome!

On Fri, Nov 24, 2017 at 3:41 AM, Enric Jaen <en...@yahoo.es.invalid>
wrote:

> I will try it and let you know
> best regards
> Enric
>    En jueves, 23 de noviembre de 2017 12:37:25 GMT, Remko Popma <
> remko.popma@gmail.com> escribió:
>
>  You know, I think we may already have something very similar...
> Take a look at the second example under Map Filter:
> https://logging.apache.org/log4j/2.x/manual/filters.html#MapFilter
>
> If you use a RegexFilter (
> https://logging.apache.org/log4j/2.x/manual/filters.html#RegexFilter)
> would
> that meet your requirements?
>
> Remko
>
>
> On Thu, Nov 23, 2017 at 9:14 PM, Enric Jaen <en...@yahoo.es.invalid>
> wrote:
>
> > Hi, Sometimes it happens that we want to see logs from a class, but not
> > all logs as it can be verbose. I think it would useful to be able to
> filter
> > logs inside a logger, specially when the logger is class.
> >
> > For example we could use include and exclude regexps:
> >
> >
> >        <logger name=" org.springframework.beans.factory.support.
> DefaultListableBeanFactory"
> > level="DEBUG">            <include string= "Creating shared instance of
> > singleton bean"            <AppenderRef ref="PROJECT" />
> >        </logger>
> >
> > or
> >        <logger name=" org.springframework.beans.factory.support.
> DefaultListableBeanFactory"
> > level="DEBUG">            <exclude string= "Returning cached instance"
> >            <AppenderRef ref="PROJECT" />
> >        </logger>
> >
> > What do you think?Regards
> > Enric
> >
>
>

Re: new feature proposal - microloggers

Posted by Enric Jaen <en...@yahoo.es.INVALID>.
I will try it and let you know
best regards
Enric
   En jueves, 23 de noviembre de 2017 12:37:25 GMT, Remko Popma <re...@gmail.com> escribió:  
 
 You know, I think we may already have something very similar...
Take a look at the second example under Map Filter:
https://logging.apache.org/log4j/2.x/manual/filters.html#MapFilter

If you use a RegexFilter (
https://logging.apache.org/log4j/2.x/manual/filters.html#RegexFilter) would
that meet your requirements?

Remko


On Thu, Nov 23, 2017 at 9:14 PM, Enric Jaen <en...@yahoo.es.invalid>
wrote:

> Hi, Sometimes it happens that we want to see logs from a class, but not
> all logs as it can be verbose. I think it would useful to be able to filter
> logs inside a logger, specially when the logger is class.
>
> For example we could use include and exclude regexps:
>
>
>        <logger name=" org.springframework.beans.factory.support.DefaultListableBeanFactory"
> level="DEBUG">            <include string= "Creating shared instance of
> singleton bean"            <AppenderRef ref="PROJECT" />
>        </logger>
>
> or
>        <logger name=" org.springframework.beans.factory.support.DefaultListableBeanFactory"
> level="DEBUG">            <exclude string= "Returning cached instance"
>            <AppenderRef ref="PROJECT" />
>        </logger>
>
> What do you think?Regards
> Enric
>
  

Re: new feature proposal - microloggers

Posted by Remko Popma <re...@gmail.com>.
You know, I think we may already have something very similar...
Take a look at the second example under Map Filter:
https://logging.apache.org/log4j/2.x/manual/filters.html#MapFilter

If you use a RegexFilter (
https://logging.apache.org/log4j/2.x/manual/filters.html#RegexFilter) would
that meet your requirements?

Remko


On Thu, Nov 23, 2017 at 9:14 PM, Enric Jaen <en...@yahoo.es.invalid>
wrote:

> Hi, Sometimes it happens that we want to see logs from a class, but not
> all logs as it can be verbose. I think it would useful to be able to filter
> logs inside a logger, specially when the logger is class.
>
> For example we could use include and exclude regexps:
>
>
>         <logger name=" org.springframework.beans.factory.support.DefaultListableBeanFactory"
> level="DEBUG">            <include string= "Creating shared instance of
> singleton bean"            <AppenderRef ref="PROJECT" />
>         </logger>
>
> or
>         <logger name=" org.springframework.beans.factory.support.DefaultListableBeanFactory"
> level="DEBUG">            <exclude string= "Returning cached instance"
>             <AppenderRef ref="PROJECT" />
>         </logger>
>
> What do you think?Regards
> Enric
>