[logback-user] Setting custom Profiler log level.

César Álvarez Núñez cesar.alvarez.nunez at gmail.com
Tue Dec 27 13:55:07 CET 2011


Thanks Ceki,

Your solution is perfect.

I've used MarkerFilter instead the custom ProfilerEnabled. Is it right? I
mean, have you proposed a custom profiler due to any performance reason?

<turboFilter class="ch.qos.logback.classic.turbo.MarkerFilter">
    <Marker>PROFILER</Marker>
    <OnMatch>ACCEPT</OnMatch>
</turboFilter>

As suggestion, it could be nice to reinforce the TurboFilter manual to
indicate that an ACCEPT means that log event will be logged always,
skipping any logger level. At least for me was not clear.

Anyway I think that a request to modify Profiler in order to set a custom
log level it is a good idea since this solution based on a TurboFilter
works with Logback but not with log4j bridge for example; but perhaps this
point should be discussed on "slf4j user list" instead of this. Sorry :-(

/César.

On Tue, Dec 27, 2011 at 12:07 PM, ceki <ceki at qos.ch> wrote:

> Hi César,
>
> My response is inline.
>
>
> On 27.12.2011 10:19, César Álvarez Núñez wrote:
>
>> Hi all,
>>
>> Our application makes an intensive use of Profiler
>> (http://www.slf4j.org/**extensions.html#profiler<http://www.slf4j.org/extensions.html#profiler>
>> ).
>> It has been very useful during the development stage an we would like to
>> keep it at production stage but there is a problem since its "log level"
>> is hard-coded to "debug".
>>
>> Currently the profiler use the same application class logger so if log
>> level is set to "info" in our production environment we lose the
>> "profiler" log :-(
>>
>> Alternatives:
>>
>>  * Use different loggers for application and profiler >-->> It requires
>>
>>    to refactoring all the code and remember that any new Profiler that
>>    will be used need to set a custom logger instead of the default
>>    class logger.
>>
>>  * Open a request to modify Profiler in order to set a custom log level.
>>
>
> This makes sense. See first if the TurboFilter described below
> approach works for you. Otherwise, please file a bug report requesting
> for this feature.
>
>   * Keep minimum log level to "debug" and make use of a Filter to accept
>>
>>    any log event with marker=PROFILER, otherwise only accept if log
>>    level >= INFO >-->> It only will work with LogBack but Profiler
>>    belongs to SLF4J so it should work with any bridge.
>>
>
> Have you considered using a TurboFilter [1]? Here is a TurboFilter
> which will enable profiler logs for all logging levels.
>
> import ch.qos.logback.classic.Level;
> import ch.qos.logback.classic.Logger;
> import ch.qos.logback.classic.turbo.**TurboFilter;
> import ch.qos.logback.core.spi.**FilterReply;
> import org.slf4j.Marker;
> import org.slf4j.MarkerFactory;
>
> public class ProfilingEnabler extends TurboFilter {
>
>  Marker profilerMarker =
>           MarkerFactory.getMarker(**Profiler.PROFILER_MARKER_NAME)**;
>
>  @Override
>  public FilterReply decide(Marker marker, Logger logger, Level level,
>                           String format, Object[] params, Throwable t){
>    if(marker == profilerMarker)   return FilterReply.ACCEPT;
>    else return FilterReply.NEUTRAL;
>  }
> }
>
> [1] http://logback.qos.ch/manual/**filters.html#TurboFilter<http://logback.qos.ch/manual/filters.html#TurboFilter>
>
>  /César.
>>
>
> Cheers,
> --
> Ceki
> http://twitter.com/#!/ceki
> ______________________________**_________________
> Logback-user mailing list
> Logback-user at qos.ch
> http://mailman.qos.ch/mailman/**listinfo/logback-user<http://mailman.qos.ch/mailman/listinfo/logback-user>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20111227/71a08eec/attachment.html>


More information about the Logback-user mailing list