Converting to slog from fern, questions


#1

Hi folks,

I’m interested in converting cernan to slog-rs from fern but have hit a couple of sticking points. You can see my in-progress work here: introduce_slog. There are two things that I haven’t managed to replicate:

  • startup time configuration of logging level: here
  • custom formatting of log message content: here

I’d really like to preserve the existing information I’m kicking out: module path, line origin, UTC timestamp, etc. The exact format doesn’t matter, of course, just so long as it’s there. It’s not clear to me if I can keep the module path without a whole lot of manual fiddling every time I make a new sub-logger.

The slog documentation does have an example on how to fiddle with log levels at runtime. I guess what I’m after, since I only want to set it once at startup, is a less manual way to get that kind of thing.

Anyway, thanks!


#2

Example of startup time configuration of logging level: https://github.com/dpc/rdedup/blob/c6dcce395910ddf2f969f31cf1aaf421fd10c2e7/src/bin.rs#L143
You can easily created custom format for values using https://docs.rs/slog/2.0.6/slog/struct.FnValue.html , but if you want completely customized formatting, you’ll have to write your own drain implementation that outputs exactly what you want, exactly where you want. Check slog-json source code for example how logging messages are outputed as Json, and slog-term for how terminal output format is implemented.

Generally I’d advise joinging slog gitter channel. More people are there and might help you.

Regards!