diff --git a/Cargo.toml b/Cargo.toml index 766b40c3c..603c7e191 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -75,7 +75,6 @@ members = [ "shed/services/common", "shed/shared_error", "shed/slog_glog_fmt", - "shed/slog_stats", "shed/sorted_vector_map", "shed/sql", "shed/sql/common", diff --git a/shed/slog_stats/Cargo.toml b/shed/slog_stats/Cargo.toml deleted file mode 100644 index f174ac920..000000000 --- a/shed/slog_stats/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -# @generated by autocargo from //common/rust/shed/slog_stats:slog_stats - -[package] -name = "slog_stats" -version = "0.1.0" -authors = ["Facebook "] -edition = "2021" -description = "Enables exposing counters for number of slog records per level" -readme = "../../README.md" -repository = "https://github.com/facebookexperimental/rust-shed" -license = "MIT OR Apache-2.0" - -[dependencies] -slog = { version = "2.7", features = ["max_level_trace", "nested-values"] } -stats = { version = "0.1.0", path = "../stats" } diff --git a/shed/slog_stats/src/lib.rs b/shed/slog_stats/src/lib.rs deleted file mode 100644 index ad4a567c8..000000000 --- a/shed/slog_stats/src/lib.rs +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under both the MIT license found in the - * LICENSE-MIT file in the root directory of this source tree and the Apache - * License, Version 2.0 found in the LICENSE-APACHE file in the root directory - * of this source tree. - */ - -//! Enables exposing counters for number of slog records per level - -#![deny(warnings, missing_docs, clippy::all, rustdoc::broken_intra_doc_links)] - -use slog::Drain; -use slog::Level; -use slog::OwnedKVList; -use slog::Record; -use stats::prelude::*; - -define_stats! { - prefix = "logging"; - critical: counter(), - error: counter(), - warning: counter(), - info: counter(), - debug: counter(), - trace: counter(), -} - -/// Drain that counts number of slog records per level using `stats` crate counters -pub struct StatsDrain { - drain: D, -} - -impl StatsDrain { - /// Create a `StatsDrain` that will pass all records and values to the given drain unchanged - /// and return the result of logging using that drain unchanged - pub fn new(drain: D) -> Self { - StatsDrain { drain } - } -} - -impl Drain for StatsDrain { - type Ok = D::Ok; - type Err = D::Err; - - fn log(&self, record: &Record<'_>, values: &OwnedKVList) -> Result { - match record.level() { - Level::Critical => STATS::critical.increment_value(1), - Level::Error => STATS::error.increment_value(1), - Level::Warning => STATS::warning.increment_value(1), - Level::Info => STATS::info.increment_value(1), - Level::Debug => STATS::debug.increment_value(1), - Level::Trace => STATS::trace.increment_value(1), - } - - self.drain.log(record, values) - } -} - -#[cfg(test)] -mod tests { - use slog::info; - use slog::o; - use slog::Discard; - use slog::Logger; - - use super::*; - - #[test] - fn test() { - let log = Logger::root(StatsDrain::new(Discard), o![]); - info!(log, "test log"); - } -}