Skip to content
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

When using suppress_basename(), the log file still starts with a '_' prefix #176

Closed
CoolLoong opened this issue Sep 24, 2024 · 1 comment

Comments

@CoolLoong
Copy link

CoolLoong commented Sep 24, 2024

flexi_logger version

flexi_logger = { version = "0.29.0", features = [
    "compress",
    "colors",
    "async",
] }

code example

let log_dir = PathBuf::from("logs");
let file_spec = FileSpec::default()
    .directory(log_dir)
    .suppress_basename()
    .suppress_timestamp()
    .o_suffix(Option::<String>::None)
    .suffix("log");

let log_to_console_format =
    |write: &mut dyn std::io::Write, now: &mut DeferredNow, record: &Record| {
        let time_prefix = now.format("%H:%M:%S");
        let binding = std::thread::current();
        let thread_name = binding.name().unwrap_or("Unknown thread");
        let level = record.level();
        let file_name = record
            .file()
            .map(|file_path| {
                Path::new(file_path)
                    .file_name()
                    .unwrap_or_else(|| std::ffi::OsStr::new("<unnamed>"))
                    .to_string_lossy()
                    .into_owned()
            })
            .unwrap_or_else(|| "<unnamed>".to_string());
        write!(
            write,
            "[{}] [{}/{}]: [{}] {}",
            style(level).paint(time_prefix.to_string()),
            style(level).paint(thread_name),
            style(level).paint(level.to_string()),
            style(level).paint(file_name),
            &record.args()
        )
    };
let log_to_file_format =
    |write: &mut dyn std::io::Write, now: &mut DeferredNow, record: &Record| {
        let time_prefix = now.format("%H:%M:%S");
        let binding = std::thread::current();
        let thread_name = binding.name().unwrap_or("Unknown thread");
        let level = record.level();
        let file_name = record
            .file()
            .map(|file_path| {
                Path::new(file_path)
                    .file_name()
                    .unwrap_or_else(|| std::ffi::OsStr::new("<unnamed>"))
                    .to_string_lossy()
                    .into_owned()
            })
            .unwrap_or_else(|| "<unnamed>".to_string());
        write!(
            write,
            "[{}] [{}/{}]: [{}] {}",
            time_prefix.to_string(),
            thread_name,
            level.to_string(),
            file_name,
            &record.args()
        )
    };

Logger::with(LogSpecification::from(config.log_level))
    .log_to_file(file_spec)
    .rotate(
        flexi_logger::Criterion::Size(10 * 1024 * 1024),
        flexi_logger::Naming::TimestampsDirect,
        flexi_logger::Cleanup::KeepLogAndCompressedFiles(0, 5),
    )
    .set_palette("b1;3;2;4;6".to_string())
    .format_for_files(log_to_file_format)
    .format_for_stderr(log_to_console_format)
    .duplicate_to_stderr(flexi_logger::Duplicate::Info)
    .write_mode(flexi_logger::WriteMode::Async)
    .start()
    .unwrap()

It outputs _r2024-09-24_16-21-18.log, but I expect is r2024-09-24_16-21-18.log

@emabee
Copy link
Owner

emabee commented Oct 2, 2024

Fixed with v0.29.1

@emabee emabee closed this as completed Oct 2, 2024
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