-
Notifications
You must be signed in to change notification settings - Fork 59
Closed
Description
Versions:
- system: Linux (Manjaro)
- rust: 1.87.0
- flexi_logger: 0.31.0
If FileSpec's directory is empty, then somewhere in the code of start will fail, the first occurrence in my case is:
| if !std::fs::metadata(p_directory)?.is_dir() { |
This happened as we passed the path verbatim that the user on the CLI had specified and then used try_from, which with a input of test.log results in a empty directory.
It works if we manually append . or make the path absolute beforehand.
Example:
fn main() -> Result<()> {
use flexi_logger::{FileSpec, Logger};
let mut logger = Logger::try_with_env_or_str("warn")
.expect("Expected flexi_logger to be able to parse env or string")
.log_to_stderr();
let filespec =
FileSpec::try_from("test.log").expect("Expected logging file to be parsed correctly");
logger = logger
.log_to_file(filespec) // no error here
.append()
.duplicate_to_stderr(flexi_logger::Duplicate::All);
// error here
logger
.start()
.expect("Expected flexi_logger to be able to start");
Ok(())
}Proposal:
- document that a directory is necessary and error otherwise (directly in
try_fromand any other functions interacting with it) - automatically add a default value (either
.like the default or making the path absolute) - making the full code work without a directory and adding a default when called for
Metadata
Metadata
Assignees
Labels
No labels