log4rs icon indicating copy to clipboard operation
log4rs copied to clipboard

Allow use of hardcoded text styles in pattern encoder

Open sfackler opened this issue 8 years ago • 8 comments

The only formatter that the pattern encoder supports which affects text style is highlight, which colors based on the log level. It should be possible to also set the text style to some specific configuration, but I'm not sure what syntax would make sense here, particularly in a way that would allow for full configuration of text color, background color, and text intensity.

sfackler avatar Apr 13 '16 05:04 sfackler

Right now the dark blue color (info level) is really hard to read on a black background.

It would be great if the defaults were improved for legibility, or if the colors could be made configurable.

dbrgn avatar Apr 12 '17 15:04 dbrgn

Your terminal controls what the colors look like: https://en.wikipedia.org/wiki/ANSI_escape_code#Colors

sfackler avatar Apr 12 '17 16:04 sfackler

Yes, but dark blue is pretty dark on most systems. Cyan as a default might be easier to read. Or a blueish color in 256-color mode.

dbrgn avatar Apr 12 '17 16:04 dbrgn

Ah, gotcha. I pulled the color selection from https://logback.qos.ch/manual/layouts.html#coloring but don't feel particularly strongly about the specifics.

sfackler avatar Apr 12 '17 16:04 sfackler

Does anyone still care about this? I'm going to close if not.

estk avatar Mar 12 '20 02:03 estk

I recently moved to this crate due to the support of both console and file logging and I can confirm that the blue color is really unreadable on my term as well with default color settings, so i don't believe this matter should be closed.

The colors should either be updated with the same as env_logger (I was previously using that crate) or they should have the ability to be configurable. So far I didn't found any functionality how can I configure the colors from the builder.

Dango-rs avatar Apr 21 '20 09:04 Dango-rs

Colour (!) me interested in this too - like @Dango-rs, I'm moving from another log framework which exposed this feature and this would be nice to have. If there's interest in taking it, I could look at putting together a PR to implement it?

I'm thinking I'd want to look at adding some sort of mapping from level to colour in PatternEncoder as a first step, then expose that as a configuration item. It feels like it would be too much to try to shoehorn into the pattern itself though, so (using the example YAML config) I'd do something like this:

  # An appender named "stdout" that writes to stdout
  stdout:
    kind: console
    encoder:
      pattern: "{d} {h({l})} {m}{n}"
      level_colors:
        INFO: Green
        WARN: Yellow
        ERROR: Red

Then go from those strings to Color values, using no colour where there's no match (so, for example, if I do TRACE: DeepPurple, that gets ignored).

Does that all seem reasonable?

tolien avatar Jun 29 '20 11:06 tolien

consider add support for level color, just like this: ColoredLevelConfig

cavivie avatar Aug 10 '22 15:08 cavivie