Log4rs - how to use different levels for appenders

Is it possible to use a specific logging level for a particular appender, let's say trace for console and error for a file?

Yes, this is possible using the filters parameter when you configure an appender (docs). Here's an example:

kind = "console"
filters = [ { kind = "threshold", level = "info" } ]

kind = "file"
path = "events.log"
filters = [ { kind = "threshold", level = "trace" } ]

appenders = ["stdout", "logfile"]

Thanks @adeschamps, that's exactly what I was looking for. Here's also how to set it up in code without yaml:

    let config = Config::builder()
                .build("console", Box::new(console)),
1 Like