Skip to content

Is structured logging à la slog supported? #1789

Answered by hawkw
dvtomas asked this question in Q&A
Discussion options

You must be logged in to vote

The setup of the logging configuration is probably slightly more complicated than usual, but the great advantage is that the hierarchy of loggers respects the structural configuration, not the call-stack configuration. Also, it is very clear in the code what particular logger each component uses.

It's certainly possible to replicate slog-style explicit context passing via a struct field or parameter. You can do this by passing around tracing::Span instances, and passing them as the parent of your spans or events explicitly. For example, to replicate your example in tracing, you could write:

impl Device {
   pub fn new(span: &tracing::Span, ...) -> Self {
     let span = tracing::info_span!

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@dvtomas
Comment options

@hawkw
Comment options

@dvtomas
Comment options

@hawkw
Comment options

Answer selected by dvtomas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #1787 on December 20, 2021 17:36.