Log4rs - different levels for appenders

My program has been panicking after I followed the code from this previous question.

I added:

filters:
  kind: threshold
  level: debug

to the following yaml:

refresh_rate: 30 seconds
appenders:
  roll:
    kind: rolling_file
    path: logs/roll.log 
    encoder: 
      pattern: "{d(%Y-%m-%d %H:%M:%S %Z)(utc)} [{l}] - {m}{n}"
    policy: 
      kind: compound
      trigger: 
        kind: size
        limit: 10 kb
      roller: 
        kind: fixed_window
        pattern: logs/roll.{}.log 
        count: 5 
        base: 1
  stdout:
    kind: console
    filters:
      kind: threshold
      level: debug
root:
  level: info
  appenders:
    - roll
    - stdout
loggers:
  app::backend::db:
    level: info
    additive: false

and I get the following error when I try to run:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Log4rs(Message("invalid type: map, expected a sequence", Some(Pos { marker: Marker { index: 44, line: 3, col: 6 }, path: "appenders" })))',

I even found this exact example in this article. I don't know if I am making some silly mistake or not, but any help would be appreciated.

It looks like you're missing the dash two lines below filters in the example. Currently your filters value is a map with the keys kind and level, but I think it wants a list of maps with those keys instead, which is hinted at by the error message.

1 Like

Thank you, that worked. I definitely ignored it because it looked a little weird. For anyone else with my problem, I had to remove the level from root as it seemed to override the level I wanted.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.