-
Notifications
You must be signed in to change notification settings - Fork 4.8k
When disk is full log rotation resulted zero size log files. #2261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for reporting. Which platform are you using? |
ubuntu 18.04 |
Hi @gabime , Any fix or workaround for this issue? |
Not sure. I need to find time to check this out. PRs are welcome. |
@kishorekrd I can't reproduce #include "spdlog/spdlog.h"
#include "spdlog/sinks/rotating_file_sink.h"
int main(int, char *[]) {
// Create a file rotating logger with 5mb size max and 4 rotated files.
auto rotating_logger = spdlog::rotating_logger_mt("some_logger_name", "/mnt/loopfs/rotating.txt", 1048576 * 5, 3);
for(int long i = 0; i < 10000000; i++)
rotating_logger->info("HELLO {}",i);
} [*** LOG ERROR #1 ] [2022-02-04 13:19:19] [some_logger_name] {Failed writing to file /mnt/loopfs/rotating.txt: No space left on device} ls /mnt/loopfs/ -l
total 12256
drwx------ 2 root root 16384 Feb 4 13:10 lost+found
-rw-r--r-- 1 root root 5242835 Feb 4 13:19 rotating.1.txt
-rw-r--r-- 1 root root 303104 Feb 4 13:19 rotating.2.txt
-rw-r--r-- 1 root root 5242835 Feb 4 13:19 rotating.3.txt
-rw-r--r-- 1 root root 1709718 Feb 4 13:19 rotating.txt |
@gabime , Thanks for trying. I see that file writing failed when disk is full. |
I couldn't reproduce. See the output of ls command above, the are not empty. Do you also see error about file renaming or just about the write? Edit: |
@kishorekrd I fixed it by checking that the file is not empty before rotating (seems to be the case when the disk is full) Could you please try latest commit and verify that it solves your problem? |
Thanks for the fix. it looks good. |
I set log rotation configuration with file size as 10Mb and up to 10 files. But when the disk is full, I ended up having 10 files all with zero size. How can I avoid this situation? I am expecting that when the write fails because of disk full situation, spdlog should not overwrite the old log files and should exit gracefully.
The text was updated successfully, but these errors were encountered: