Skip to content

[HELP] Adding custom fields to all logs without propagating them to log usages? #185

@nerodono

Description

@nerodono

I want to turn off and on logs in the same module selectively (some part of code should have logs, some other part don't) and add custom fields to each log without propagating those fields to log::{warn,info,debug, ...} usages. Intuitively, fastrace integration should do this, however:

let span = Span::root("root", SpanContext::random()).with_property(|| ("component", "database"));
async move {
    log::info!("Test");
}.in_span(span).await;

Doesn't report component=database. How can I achieve that properly? I can't use Metadata::target (can I? As far as I can see, target represents crate name), since everything occurs in the same crate.

And logforth lacks some explanations, as an example:

Metadata::target
Get the target

What's the target?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions