Separate thread for compressing logfiles in Logback?

java, logback, logging, performance

Solution

I have investigated logback-1.0.3. Let's consider use case:

- You invoke Logger#error(String) in your code.

- Your data filtered according Logger configuration.

- Will invoke Appenders after buildLoggingEventAndAppend and callApenders

- In your case will invoke append method in OutputStreamAppender.

- Trigger based RollingFileAppender will invoke rollover when event triggered.

- In rollover method will invoke appropriate compress method.

As you can see all stuff will be logged and compressed in the same thread as data logged. And thus you shouldn't log in time critical threads.

Personally, I suppose logging in the same thread is not critical for majority applications, but it depends strongly from your environment, perfomance requirements, e.t.c.

If you want to log data asynchronously you can use AsyncAppender. In this case compressing also will be in separate thread.

Problem

In Logback, we could config as: 1 when the size of the logfile reaches like 50MB, rotate the file and compress it. So I wonder will it do the compress stuff in a separate thread, will it have any performance issue?

Original source