Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Structured logging #12

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft

Structured logging #12

wants to merge 7 commits into from

Conversation

tqwewe
Copy link
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.

None yet

1 participant