emabee / flexi_logger

A flexible logger for rust programs that can write to stderr, stdout, and/or to log files
Apache License 2.0
307 stars 50 forks source link

Rotate files was not triggered #167

Closed longzou closed 2 months ago

longzou commented 2 months ago

The logger's configure as below:

Logger::with(logger_builder.build()).format(fmt) .adaptive_format_for_stdout(flexi_logger::AdaptiveFormat::WithThread) .cleanup_in_background_thread(true) .append() .print_message() .rotate(flexi_logger::Criterion::Size(8196), flexi_logger::Naming::Timestamps, flexi_logger::Cleanup::KeepLogFiles(5)) .write_mode(write_mode);

The log files was not removed during the app running.

emabee commented 2 months ago

You need to use log_to_file to tell flexi_logger that it should write its output to files, and which files this should be. Only then will the rotation config become relevant.

PS: flexi_logger does not use different types for its builder - this could be used to e.g. enable use of rotate only if log_to_file was used before; the compiler would then help to avoid such issues. Earlier attempts of doing so resulted in an API doc that was much harder to read, so I abdicated it.