Skip to content

Structured logging#12

Draft
tqwewe wants to merge 7 commits into
mainfrom
structured-logging
Draft

Structured logging#12
tqwewe wants to merge 7 commits into
mainfrom
structured-logging

Conversation

@tqwewe
Copy link
Copy Markdown
Member

@tqwewe tqwewe commented Mar 7, 2023

Adds support for additional structured data in logs which are represented serialized using JSON.

This allows for logging variables that implement Serialize using the logging macros.
If the type doesn't implement serialize, the % and ? prefixes can be used to convert it to a string using its Display or Debug implementation.

Variables can be logged with the % prefix, which converts the value to a string using Display:

let err = "too many attempts";
error!(%err, "An error occurred");

Variables can be logged with the ? prefix, which converts the value to a string using Debug:

let err = "too many attempts";
error!(?err, "An error occurred");

Or without any prefix, which uses the serde_json::to_value implementation:

let err = "too many attempts";
error!(err, "An error occurred");

The syntax for the macros are modified versions of the tracing crate's macros, so the syntax is essentially the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant