Skip to content

refactor: Derive Clone for RustLogFilter and Directive#237

Merged
tisonkun merged 1 commit into
fast:mainfrom
pol-epsevg:main
Jul 25, 2026
Merged

refactor: Derive Clone for RustLogFilter and Directive#237
tisonkun merged 1 commit into
fast:mainfrom
pol-epsevg:main

Conversation

@pol-epsevg

Copy link
Copy Markdown
Contributor

I was writing something using logforth, and instead of using different filters for different appenders (Like in the example from percas), I wanted to reuse a single filter:

let filter = RustLogFilterBuilder::try_from_spec(&configuration.filter)?.build();

let mut builder = logforth::starter_log::builder();

// If configured, add an opentelemetry exporter to the logger
if let Some(otlp_config) = &configuration.opentelemetry {
    let appender = {
        let exporter = LogExporter::builder()
            .with_tonic()
            .with_endpoint(&otlp_config.endpoint)
            .with_protocol(Protocol::Grpc)
            .build()?;

        OpentelemetryLogBuilder::new(otlp_config.service_name.clone(), exporter)
            .label("service.name", otlp_config.service_name.clone())
            .build()
    };

    // First filter use
    builder = builder.dispatch(|b| b.filter(filter).append(appender));
};

// If enabled, also log to stderr
if configuration.stderr {
    builder = builder.dispatch(|b| {
        // Can't use that same filter a second time!
        b.filter(filter)
            .append(Stderr::default().with_layout(TextLayout::default()))
    });
}

My obvious next step is to .clone() the filter, but turns out that isn't implemented. Is there any particluar reason? Am I missing something?

@pol-epsevg pol-epsevg changed the title Derive Clone for RustLogFilter and Directive refactor: Derive Clone for RustLogFilter and Directive Jul 25, 2026

@tisonkun tisonkun left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reasonable. Thanks!

@tisonkun
tisonkun merged commit 37f10b0 into fast:main Jul 25, 2026
10 checks passed
@pol-epsevg

Copy link
Copy Markdown
Contributor Author

Thanks tison, appreciated.

@tisonkun

Copy link
Copy Markdown
Contributor

I'm going to review the other PR and do some API changes to release a new version next week.

Feel free to ping me if I miss this schedule.

I hope a logforth-core 0.5 would be a candidate for logforth-core 1.0.

If you're interested, feel free to drop your ideas on #225 and #205

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.

2 participants