[logback-user] Logging to database

Ralph Goers rgoers at apache.org
Tue Jan 13 06:06:33 CET 2009


On Jan 12, 2009, at 8:50 AM, Aswani wrote:

>
> Thank you Ceki.
>
> Is there any appender in Logback to buffer all events of one  
> user(per client
> request)?
> Is the CyclicBufferAppender or WriterAppender suitable for this  
> requirement?
>
> Yes, writing to Database is slower than writing to file. That the  
> reason we
> are thinking of buffering the events and write them at once as a  
> single
> message(clob data). We are also thinking of making this DB process
> asynchronous.

I am curious as to why you want to buffer per user? Is that a real  
requirement or are you just trying to figure out when to flush them?  
The approach I have seen taken is to have a buffer with a fixed number  
of records along with a timeout.  The timeout ensures that the buffer  
doesn't sit there partly full for too long.

Buffering per request is a little difficult. You'd need to have a  
buffer attached to a ThreadLocal so that it can be located without  
requiring the Request object. But if the request thread does work on  
another thread as well things would get messy. Plus, the appender  
can't really know when to flush the buffer without the application  
forcing it.

Ralph


More information about the Logback-user mailing list