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

Output logs in JSON with QW_LOG_FORMAT=json #5672

Merged
merged 1 commit into from
Feb 10, 2025
Merged

Conversation

guilload
Copy link
Member

@guilload guilload commented Feb 7, 2025

Description

Per title.

How was this PR tested?

Ran locally and inspected logs manually

@guilload guilload requested a review from rdettai February 7, 2025 19:37
@guilload guilload linked an issue Feb 7, 2025 that may be closed by this pull request

enum EventFormat<'a> {
Full(Format<Full, UtcTime<Vec<BorrowedFormatItem<'a>>>>),
Json(tracing_subscriber::fmt::format::Format<tracing_subscriber::fmt::format::Json>),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Json(tracing_subscriber::fmt::format::Format<tracing_subscriber::fmt::format::Json>),
Json(Format<tracing_subscriber::fmt::format::Json>),

Comment on lines 123 to 126
enum EventFormat<'a> {
Full(Format<Full, UtcTime<Vec<BorrowedFormatItem<'a>>>>),
Json(tracing_subscriber::fmt::format::Format<tracing_subscriber::fmt::format::Json>),
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any strong reason for using a custom event format rather than a boxed layer? Maybe from a performance point of view enum is a tiny bit better, but boxing would be substantially simpler.

fn fmt_layer<S>(level: Level) -> Box<dyn Layer<S> + Send + Sync + 'static>
where
S: for<'a> LookupSpan<'a>,
S: tracing::Subscriber,
{
if *ENABLE_VERBOSE_JSON_LOGS {
json_fmt_layer(level).boxed()
} else {
compact_fmt_layer(level).boxed()
}
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assumed we didn't go for a boxed implementation in the first place for a good reason, so I also added unboxed code. I'm open to a refactor that uses the same code in cli and lambda and potentially uses boxed layers.

registry
.with(telemetry_layer)
.with(
tracing_subscriber::fmt::layer()
.event_format(event_format)
.fmt_fields(fmt_fields)
.with_ansi(ansi_colors),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does it mean to set ansi to true if the format is json?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No op.

@guilload guilload force-pushed the guilload/json-log-format branch from f946626 to 9d19d56 Compare February 10, 2025 21:05
@guilload guilload merged commit 647d02e into main Feb 10, 2025
8 checks passed
@guilload guilload deleted the guilload/json-log-format branch February 10, 2025 21:48
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.

Offer the possibility to output logs in json format
2 participants