From 861813c1897216984194d1a838eb39dde13c525d Mon Sep 17 00:00:00 2001 From: Nathan Gill Date: Wed, 25 Feb 2026 08:22:58 +0000 Subject: [PATCH] refactor(util): move `LogLevel` enum into `util` module - move `LogLevel` to `util`, with other arg-related enums - impl `From` on `tracing::level_filters::LevelFilter` to simplify conversion. --- src/args.rs | 25 ++----------------------- src/main.rs | 2 +- src/util.rs | 21 +++++++++++++++++++++ 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/args.rs b/src/args.rs index 1906002..3c47138 100644 --- a/src/args.rs +++ b/src/args.rs @@ -4,7 +4,7 @@ use std::path::{Path, PathBuf}; use clap::{ - Command, CommandFactory, FromArgMatches, Parser, Subcommand, ValueEnum, + Command, CommandFactory, FromArgMatches, Parser, Subcommand, builder::{ Styles, styling::{AnsiColor, Effects}, @@ -12,28 +12,7 @@ use clap::{ }; use clap_complete::{Shell, aot::generate as generate_completions}; -use crate::util::{BackgroundImageScale, BackgroundType, FontSlant, FontWeight, Rgba}; - -#[derive(Copy, Clone, Debug, ValueEnum)] -pub enum LogLevel { - Trace, - Debug, - Info, - Warn, - Error, -} - -impl LogLevel { - pub fn to_level(self) -> tracing::Level { - match self { - Self::Trace => tracing::Level::TRACE, - Self::Debug => tracing::Level::DEBUG, - Self::Info => tracing::Level::INFO, - Self::Warn => tracing::Level::WARN, - Self::Error => tracing::Level::ERROR, - } - } -} +use crate::util::{BackgroundImageScale, BackgroundType, FontSlant, FontWeight, LogLevel, Rgba}; /// Customisable, minimalist screen locker for Wayland #[derive(Parser, Debug)] diff --git a/src/main.rs b/src/main.rs index d077a40..610f6ab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -99,7 +99,7 @@ async fn main() { tracing_subscriber::fmt() .with_timer(tracing_subscriber::fmt::time::uptime()) - .with_max_level(args.log_level.to_level()) + .with_max_level(args.log_level) .init(); let now = chrono::Local::now(); diff --git a/src/util.rs b/src/util.rs index 31e4711..44e7668 100644 --- a/src/util.rs +++ b/src/util.rs @@ -134,6 +134,27 @@ impl From for cairo::FontWeight { } } +#[derive(Debug, Copy, Clone, ValueEnum)] +pub enum LogLevel { + Trace, + Debug, + Info, + Warn, + Error, +} + +impl From for tracing::level_filters::LevelFilter { + fn from(value: LogLevel) -> Self { + match value { + LogLevel::Trace => Self::TRACE, + LogLevel::Debug => Self::DEBUG, + LogLevel::Info => Self::INFO, + LogLevel::Warn => Self::WARN, + LogLevel::Error => Self::ERROR, + } + } +} + pub fn open_shm() -> Option { let mut retries = 100;