estk / log4rs

A highly configurable logging framework for Rust
Apache License 2.0
973 stars 143 forks source link

Logging pattern does not depict logs as I declared it #371

Open EvilWatermelon opened 2 months ago

EvilWatermelon commented 2 months ago

I want that my log looks like this:

2024-05-02T10:45:28 [INFO] actix_server::server - Actix runtime found; starting in Actix runtime

But that does not work and looks like this:

2024-05-02T10:45:28.658835804+02:00 INFO actix_server::server - Actix runtime found; starting in Actix runtime

And I also want to use colors but that does not work either. What am I doing wrong?

appenders:
  stdout:
    kind: console
  requests:
    kind: threshhold
    encoder:
      kind: pattern
      pattern: "{h(%Y-%m-%d %H:%M:%S)} | {({l}):5.5} | [{f}:{L}] — {m}{n}"
      level_colors:
        INFO: Green
        WARN: Yellow
        ERROR: Red
        DEBUG: Orange
root:
  level: debug
  appenders:
    - stdout
loggers:
  app::requests:
    level: info
    appenders:
      - requests
    additive: true
bconn98 commented 2 months ago
  1. Colors: We don't yet support modifying the highlight scheme. Here's an old PR that started the process: https://github.com/estk/log4rs/pull/224
  2. It looks like the only issue is related to the formatting of seconds? It looks like the crate we use to format time may have had some modifications. I'll take a look.
bconn98 commented 2 months ago

@EvilWatermelon I took a look and chrono has not changed their formatting. I ran some tests and believe "{h({d(%Y-%m-%d %H:%M:%S)} [{l:<5.5}] {M} - {m})}{n}" is the pattern you're looking for. I used the compile_time_config example to test it.

bconn98 commented 1 month ago

@EvilWatermelon Please close this if you're all set