Skip to content

Panic on name conflict for all possible file names during initialization #1

@flocked-agriculture

Description

@flocked-agriculture

Is your feature request related to a problem? Please describe.
It is a little concerning that the rotating file handler will silently open a file if it already exists and write to it. This could corrupt the file so neither the old or new data can be read. This can easily be handled outside the library which is what makes it a feature request and not a bug but it seems valuable to handle within the library.

Describe the solution you'd like
I want to see this panic or err loud and fast if there is a file conflict. I could see erring in stead of panic so that the parent process has the opportunity to cleanup and retry.

let path = Path::new(base_name);
assert!(!path.exists());
for i in 0..backup_count {
     let path = Path::new(format!("{}.{}", base_name, i));
     assert!(!path.exists());
}

Describe alternatives you've considered
I considered renaming any existing file so there is no conflict before proceeding but that adds complexity to this module that is not inline with its intent. Renaming existing files also can have its own unintended consequences.

Additional context

  1. some contexts might require that the rotating_file_handler can resume logging after a reboot such as a power cycle. in this case panicing would be a bad idea. This situation should be handled through a resume flag that ensures this panic wont occur and that the header wont be reapplied in the middle of the file.

Metadata

Metadata

Labels

enhancementNew feature or request

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions