[slf4j-user] Configuration properties within logger context

Daniel Ferber dffforum at gmail.com
Fri Feb 10 16:49:05 CET 2012


Hi Ceki,

Sorry I was not able to explain my intention. Here is an example.



A worker class iterates over data until a result is found. The worker
allows to register a callback that executes nextIteration() on each
iteration. The callback logs some properties that describe the progress of
the worker. But writes log only on every “interval” calls, to prevent
cluttering the log, since the worker will execute a million of iterations.


Worker w = new Worker().
w.addCallback(new ContinuousCallback()) {

            int counter  = 0;

void nextIteration() {

            int interval =
Integer.parseInt(logger.getProperty(“worker.interval”));

            if (logger.isInforEnabled() && counter++ % interval == 0)  {

                        // collect attributesArray

                        logger.info(“i={}, convergence={}, ... ",
attributesArray) ;

            }

}
}



I would like to get the “interval” from the log configuration (eg, for
logback):

<configuration>

            <property name=“worker.interval” value=“100” />

            <logger name="callback" level="INFO" />

</configuration>



I think that “interval” is a property that controls how data is logged and
I think it would be more elegant being able to set the property together
with the logger configuration.



There seems that I can get properties from a LoggerContext withing logback,
but I understand that slf4j does not exposes this context.



Best regards,

Daniel Felix Ferber

2012/2/9 ceki <ceki at qos.ch>

>
> Hi Daniel,
>
> I don't follow you. Could you provide an *example* of what you have in
> mind (assume you have complete liberty with the SLF4J API) ?
>
> --
> Ceki
> http://twitter.com/#!/ceki
>
>
> On 09.02.2012 14:45, Daniel Felix Ferber wrote:
>
>> Hi all,
>>
>> I was wondering about slf4j being able to get properties defined within
>> the
>> configuration file form the logger framework (eg logback or log4j). Would
>> that
>> be a reasonable use for slf4j?
>>
>> 1) I would configure the granularity (amount of content) of a log message
>> that
>> reports the result of a long-running execution.
>>
>> 2) Also, I would configure the number of step between two log messages on
>> a
>> long-running task.
>>
>> For the first case, I could define several loggers (a simple one, a
>> detailed
>> one). I don't think I should use two levels, since the report cannot be
>> considered 'info', not 'debug' or 'trace'.
>>
>> For the second case, I am not sure how to handle it. Currently the
>> application
>> has a configuration property that defines how log will behave (number of
>> steps,
>> amount of details). But taking it rigorously, these are not application
>> configuration, but logger configuration.
>>
>> Best regards,
>> Daniel Felix Ferber
>>
>
>
> ______________________________**_________________
> slf4j-user mailing list
> slf4j-user at qos.ch
> http://mailman.qos.ch/mailman/**listinfo/slf4j-user<http://mailman.qos.ch/mailman/listinfo/slf4j-user>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/slf4j-user/attachments/20120210/292d92f8/attachment.html>


More information about the slf4j-user mailing list