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;