8000 When disk is full log rotation resulted zero size log files. · Issue #2261 · gabime/spdlog · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Closed
kishorekrd opened this issue Jan 29, 2022 · 9 comments
Closed

When disk is full log rotation resulted zero size log files. #2261

kishorekrd opened this issue Jan 29, 2022 · 9 comments

Comments

@kishorekrd
Copy link

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.

@gabime
Copy link
Owner
gabime commented Jan 29, 2022

Thanks for reporting. Which platform are you using?

@kishorekrd
Copy link
Author

ubuntu 18.04

@kishorekrd
Copy link
Author

Hi @gabime , Any fix or workaround for this issue?

@gabime
Copy link
Owner
gabime commented Feb 2, 2022

Not sure. I need to find time to check this out. PRs are welcome.

@gabime
Copy link
Owner
gabime commented Feb 4, 2022

@kishorekrd I can't reproduce
I filled the disk and the logger behaved as expected.

#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}
[
LOG ERROR #7175 ] [2022-02-04 13:19:20] [some_logger_name] {Failed writing to file /mnt/loopfs/rotating.txt: No space left on device}
[
LOG ERROR #9579 ] [2022-02-04 13:19:21] [some_logger_name] {Failed writing to file /mnt/loopfs/rotating.txt: No space left on device}
[
LOG ERROR #15589 ] [2022-02-04 13:19:22] [some_logger_name] {Failed writing to file /mnt/loopfs/rotating.txt: No space left on device}
[
LOG ERROR #21599 ] [2022-02-04 13:19:24] [some_logger_name] {Failed writing to file /mnt/loopfs/rotating.txt: No space left on device}
[
LOG ERROR #27609 ***] [2022-02-04 13:19:25] [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

@kishorekrd
Copy link
Author

@gabime , Thanks for trying. I see that file writing failed when disk is full.
When rotation happens, it has to rename all the existing log files and create new log file. But if disk becomes full in this situation, it is failing and making all the log files with zero size. I think rotation should pause if the disk is full.

@gabime
Copy link
Owner
gabime commented Feb 5, 2022

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?
Maybe provide a code to reproduce?

Edit:
I managed to reproduce now..

@gabime gabime closed this as completed in 7536192 Feb 5, 2022
@gabime gabime reopened this Feb 5, 2022
@gabime
Copy link
Owner
gabime commented Feb 5, 2022

@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?

@kishorekrd
Copy link
Author

Thanks for the fix. it looks good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0