[logback-user] Handling log events happening before configuration is ready?
brett.walker at geometryit.com
Tue Sep 4 15:30:17 CEST 2012
When I first discovered logback about two years ago I saw this potential problem. I thought some sort of cyclic buffer as used by logback's status listener was a possible solution. The problem I saw was that filters, formatters and encoders were not set. Thus the logging event had to be stored in a 'raw' format (loggingEvent or something similar was sufficient) to be replayed back in an orderly manner, once the configuration of logback was complete. From memory, it was the orderly replay that I was yet to fully solve and the transition from a cyclic buffer to the effective logger as described in the configuration file.
I could see the scenario where application, upon startup, had not yet fully finished establishing it's environment yet third party libraries are emitting crucial log statements.
Some sort of buffer is needed. In most case it should not be needed.
It raises another question; "How to configure this temporary buffer?"
On 04/09/2012, at 10:50 PM, "ceki" <ceki at qos.ch> wrote:
> How much time are we talking about between logback initialization and
> the time where the value of the property is known?
> On 04.09.2012 14:38, Thorbjørn Ravn Andersen wrote:
>> We have done plain old “just log to a new file for the duration of the
>> program – delete old logs daily” for several years now and found it
>> works well for us.
>> Now I have a rather tricky situation where part of the file name to be
>> used by (a subclass of) FileAppender needs to be supplied by my code,
>> but the initialization phase of the application contains log statements
>> triggering the initialization of logback _/before/_ the property
>> referred to by the FileAppender name string is set causing the log file
>> to have an incorrect name.
>> Basically what I have found to be the behavior I want is for logback to
>> await opening the file and write data before I say it can.
>> Question is how I can do this within the limits of logback. Can I tell
>> logback to just buffer events in memory (this will only be for a few
>> seconds, and memory will most likely not be an issue) – some kind of
>> valve? Can I tell FileAppender to write to a temporary file and rename
>> it whenever the name is ready (perhaps using some of the Policies from
>> Any suggestions on how to handle this?
>> Note: As we restart our application daily we do not need
>> RollingFileAppender for our general logging – instead we have subclassed
>> FileAppender to remove “older than X days” files from the target
>> folder. This has proven to work very well for our scenario.
> Logback-user mailing list
> Logback-user at qos.ch
More information about the Logback-user