How to handle disk full errors when logging in?

I use slf4j + logback to register in our application. We used to use jcl + log4j and moved recently.

Due to the large amount of registration in our application, there is a possibility of a full disk full in the working environment. In such cases, we need to stop logging, and the application should work fine. What I found from the Internet is that we need to poll the StatusManager log for such errors. But this will add a logback dependency to the application. For log4j, I found that we can create an Appender that stops registering in such scripts. This will again cause the application to depend on log4j.

Is there a way to configure this with only slf4j, or is there any other mechanism for this?

+8
java logging slf4j logback
source share
3 answers

You do not need to do anything or customize. Logback is designed to handle this situation pretty well. As soon as the target disk is full, logback FileAppender will stop writing to it for a certain short period of time. As soon as this delay expires, he will try to recover. If the recovery attempt fails, the waiting period increases gradually to 1 hour. If the recovery attempt succeeds, FileAppender will start again.

The process is fully automated and easily distributed by RollingFileAppender . See Also graceful recovery.

In a more personal note, elegant restoration is one of my favorite magazine features.

+7
source share

You can try to extend the slf4j.Logger class, in particular, information, debugging, tracing and other methods, and manually request the available space (via File.getUsableSpace ()) before each call.

This way you don’t need an application dependency

0
source share

2 real options:

  • add cron task to linux (or scheduled on windows) to clear your mess (including gzip if needed).
  • buy a large hard drive and manually perform maintenance

  • + - decrease registration

The disk is completely similar to OOM, you cannot know what is not working. Working with memory (or disk) is to prevent it. There could be many cases where additional disk space might be required and the task failed.

0
source share

All Articles