slog icon indicating copy to clipboard operation
slog copied to clipboard

Allow `Debug`-based formatting in `slog_debug!` and `slog_trace!`

Open sanmai-NL opened this issue 7 years ago • 5 comments

In many Rust projects, Clippy is used to detect suboptimal code. Clippy may give a warning whenever you leave Debug-based formatting in your code.

warning: use of `Debug`-based formatting
   --> src/main.rs:381:48
    |
381 |     slog_debug!(logger, "Dump of Blah struct: {:?}", &blah);
    |                                                ^^^^^^^^^^^^^^
    |
    = note: #[warn(use_debug)] implied by #[warn(clippy_pedantic)]
    = help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#use_debug

With slog_debug! and slog_trace!, however, we can be sure that Debug-based formatting is permissible.

Therefore I propose to add

#[allow(use_debug)]

inside these macros.

sanmai-NL avatar May 07 '17 11:05 sanmai-NL

I guess it makes sense.

Note. A preferred method of printing Debug would be via key-value: https://docs.rs/slog/2.0.4/slog/macro.log.html#fmtdisplay-and-fmtdebug-values . We need to make sure it is also covered.

Feel free to submit a PR. I might get to it at some point.

dpc avatar May 07 '17 16:05 dpc

Could you please explain in what sense that KV syntax is better than a format string to print values with Debug-based formatting? There is one motivation in the docs you refer to, but that seems to not apply to format strings?

sanmai-NL avatar May 07 '17 16:05 sanmai-NL

Format string support is there as an escape hatch for people that really need it (or are stubborn, don't like structured logging, and just want other slog features :D ).

If you search for "why use structured logging" you'll find plenty of writing by structured logging advocates. Comes down to not smashing everything into a string that is hard to parse, and instead keeping the message, contexts of logging, and data associated, so it's easier to process.

dpc avatar May 07 '17 16:05 dpc

I came in searching for a way to just use a Debug as a value in the kv portion of the macro. Maybe that would be a decent middle ground? I am sure this has been discussed, is there motivation behind not implementing (into?) slog::Value for Debug?

rrichardson avatar Aug 29 '17 20:08 rrichardson

IIRC, no default impl in Rust.

dpc avatar Aug 30 '17 12:08 dpc