Hi, I managed to run log4rs with a single logfile successfully, but when I try the rolling_appender I get the following errors:
log4rs: error deserializing appender rolling_appender: no appender deserializer for kind `compound` registered
log4rs: Reference to nonexistent appender: `rolling_appender`
this is my Cargo.toml:
[package]
name = "logger"
version = "0.1.0"
edition = "2024"
[dependencies]
log = "0.4.28"
log4rs = { version = "1.4.0", features = ["rolling_file_appender", "compound_policy", "time_trigger", "fixed_window_roller"] }
I also tried:
log4rs = { version = "1.4.0", features = ["all_components"] }
and received the same error.
My logging_config.yaml is:
appenders:
console_appender:
kind: console
encoder:
pattern: '{h({d(%Y-%m-%d %H:%M:%S)} - {l}: {m}{n})}'
rolling_appender:
kind: rolling_file
path: logs/commonpaths.log
# For Windows, use path: "$ENV{USERPROFILE}/logs/commonpaths.log"
# For Linux/macOS, use path: "$ENV{HOME}/logs/commonpaths.log"
append: true
encoder:
pattern: '{h({d(%Y-%m-%d %H:%M:%S)} - {l}: {m}{n})}'
policy:
kind: compound
trigger:
kind: time
interval: 1 day
modulate: false
max_random_delay: 0
roller:
kind: fixed_window
base: 1
count: 5
pattern: logs/commonpaths.log._$TIME{%Y-%m-%d}.gz
root:
level: trace
appenders:
- console_appender
- rolling_appender
and in my main.rs, I call:
log4rs::init_file("logging_config.yaml", Default::default()).unwrap();
Thank you for your help.
jer
2
Hi, and welcome to the Rust Users Forum! Please refer to the Code Formatting Guidelines of this forum to correctly format your code snippets:
Thank you for your email, I have made the corrections
Thank you for your guidance, I’ve edited my question.
After a quick look at the repository, it seems that you need "config_parsing" and "yaml_format" features as well.
Thank you for your help, but I followed your suggestion and I received the same error message.
The error was resolved by fixing the indentations in my logging_config.yaml as suggested here:
A snow flake can start an avalanche 
1 Like