From ecea63aa1008761e72988020f62388da88e5b796 Mon Sep 17 00:00:00 2001 From: Ryan Butler Date: Wed, 11 Dec 2024 14:21:36 -0600 Subject: [PATCH] refactor(mcu-util): use orb-telemetry (#321) --- Cargo.lock | 1 + Cargo.toml | 1 + mcu-util/Cargo.toml | 7 ++++--- mcu-util/src/logging.rs | 24 ------------------------ mcu-util/src/main.rs | 3 +-- telemetry/src/lib.rs | 3 +++ 6 files changed, 10 insertions(+), 29 deletions(-) delete mode 100644 mcu-util/src/logging.rs diff --git a/Cargo.lock b/Cargo.lock index ce9cd635..e83db7a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4548,6 +4548,7 @@ dependencies = [ "image 0.24.8", "orb-build-info 0.0.0", "orb-mcu-interface", + "orb-telemetry", "tokio", "tracing", "tracing-subscriber", diff --git a/Cargo.toml b/Cargo.toml index 788490f0..08206562 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -89,6 +89,7 @@ orb-attest-dbus.path = "attest/dbus" orb-build-info.path = "build-info" orb-const-concat.path = "const-concat" orb-header-parsing.path = "header-parsing" +orb-mcu-interface.path = "mcu-interface" orb-security-utils.path = "security-utils" orb-slot-ctrl.path = "slot-ctrl" orb-telemetry.path = "telemetry" diff --git a/mcu-util/Cargo.toml b/mcu-util/Cargo.toml index 2d340675..10d9f790 100644 --- a/mcu-util/Cargo.toml +++ b/mcu-util/Cargo.toml @@ -15,13 +15,14 @@ async-trait = "0.1.77" clap.workspace = true color-eyre.workspace = true crc32fast = "1.3.2" +futures.workspace = true image = "0.24.8" -orb-mcu-interface.path = "../mcu-interface" +orb-build-info.workspace = true +orb-mcu-interface.workspace = true +orb-telemetry.workspace = true tokio.workspace = true tracing-subscriber.workspace = true tracing.workspace = true -futures.workspace = true -orb-build-info.path = "../build-info" [build-dependencies] orb-build-info = { path = "../build-info", features = ["build-script"] } diff --git a/mcu-util/src/logging.rs b/mcu-util/src/logging.rs deleted file mode 100644 index 12518879..00000000 --- a/mcu-util/src/logging.rs +++ /dev/null @@ -1,24 +0,0 @@ -use color_eyre::eyre::Result; -use tracing::level_filters::LevelFilter; -use tracing_subscriber::layer::SubscriberExt; -use tracing_subscriber::util::SubscriberInitExt; -use tracing_subscriber::{EnvFilter, Layer}; - -/// Initialize the logger -pub fn init() -> Result<()> { - let filter = EnvFilter::builder() - .with_default_directive(LevelFilter::INFO.into()) - .from_env_lossy(); - - let stdout_log = tracing_subscriber::fmt::layer() - .compact() - .with_writer(std::io::stdout) - .with_filter(filter); - - let registry = tracing_subscriber::registry(); - #[cfg(tokio_unstable)] - let registry = registry.with(console_subscriber::spawn()); - registry.with(stdout_log).try_init()?; - - Ok(()) -} diff --git a/mcu-util/src/main.rs b/mcu-util/src/main.rs index 5495aa59..435c6bd5 100644 --- a/mcu-util/src/main.rs +++ b/mcu-util/src/main.rs @@ -17,7 +17,6 @@ use tracing::{debug, error}; use crate::orb::Orb; -mod logging; mod orb; static BUILD_INFO: BuildInfo = make_build_info!(); @@ -268,7 +267,7 @@ fn clap_v3_styles() -> Styles { #[tokio::main] async fn main() -> Result<()> { color_eyre::install()?; - logging::init()?; + orb_telemetry::TelemetryConfig::new().init(); let args = Args::parse(); diff --git a/telemetry/src/lib.rs b/telemetry/src/lib.rs index b5cd6b10..a33dd64f 100644 --- a/telemetry/src/lib.rs +++ b/telemetry/src/lib.rs @@ -15,6 +15,7 @@ impl TelemetryConfig { /// Provides all required arguments for telemetry configuration. /// - `log_identifier` will be used for journald, if appropriate. #[expect(clippy::new_without_default, reason = "may add required args later")] + #[must_use] pub fn new() -> Self { Self { syslog_identifier: None, @@ -27,6 +28,7 @@ impl TelemetryConfig { /// Enables journald, and uses the provided syslog identifier. /// /// If you run the application in a tty, stderr will be used instead. + #[must_use] pub fn with_journald(self, syslog_identifier: &str) -> Self { Self { syslog_identifier: Some(syslog_identifier.to_owned()), @@ -36,6 +38,7 @@ impl TelemetryConfig { /// Override the global filter to a custom filter. /// Only do this if actually necessary to deviate from the orb's defaults. + #[must_use] pub fn with_global_filter(self, filter: EnvFilter) -> Self { Self { global_filter: filter,