// Copyright 2025 New Vector Ltd. // // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial // Please see LICENSE files in the repository root for full details. use std::borrow::Cow; use tower_layer::Layer; use tower_service::Service; use crate::LogContextService; /// A layer which creates a log context for each request. pub struct LogContextLayer { tagger: fn(&R) -> Cow<'static, str>, } impl Clone for LogContextLayer { fn clone(&self) -> Self { Self { tagger: self.tagger, } } } impl LogContextLayer { pub fn new(tagger: fn(&R) -> Cow<'static, str>) -> Self { Self { tagger } } } impl Layer for LogContextLayer where S: Service, { type Service = LogContextService; fn layer(&self, inner: S) -> Self::Service { LogContextService::new(inner, self.tagger) } }