cli/args: Use tracing::Level directly

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
This commit is contained in:
Andrew Gunnerson
2024-08-18 23:58:11 -04:00
parent 0bebf120c6
commit eeea9f41b4
2 changed files with 8 additions and 40 deletions
+4 -37
View File
@@ -37,39 +37,6 @@ pub enum Command {
MagiskInfo(boot::MagiskInfoCli),
}
#[derive(Debug, Clone, Copy, ValueEnum)]
pub enum LogLevel {
Trace,
Debug,
Info,
Warn,
Error,
}
impl LogLevel {
fn as_level(self) -> Level {
match self {
Self::Trace => Level::TRACE,
Self::Debug => Level::DEBUG,
Self::Info => Level::INFO,
Self::Warn => Level::WARN,
Self::Error => Level::ERROR,
}
}
}
impl Default for LogLevel {
fn default() -> Self {
Self::Info
}
}
impl fmt::Display for LogLevel {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.to_possible_value().ok_or(fmt::Error)?.get_name())
}
}
#[derive(Debug, Clone, Copy, ValueEnum)]
pub enum LogFormat {
Short,
@@ -96,8 +63,8 @@ pub struct Cli {
pub command: Command,
/// Lowest log message severity to output.
#[arg(long, global = true, value_name = "LEVEL", default_value_t)]
pub log_level: LogLevel,
#[arg(long, global = true, value_name = "LEVEL", default_value_t = Level::INFO)]
pub log_level: Level,
/// Output format for log messages.
#[arg(long, global = true, value_name = "FORMAT", default_value_t)]
@@ -124,11 +91,11 @@ impl FormatTime for ShortUptime {
}
}
pub fn init_logging(log_level: LogLevel, log_format: LogFormat) {
pub fn init_logging(log_level: Level, log_format: LogFormat) {
let builder = tracing_subscriber::fmt()
.with_writer(io::stderr)
.with_ansi(io::stderr().is_terminal())
.with_max_level(log_level.as_level());
.with_max_level(log_level);
match log_format {
LogFormat::Short => {
+4 -3
View File
@@ -5,8 +5,9 @@
use std::{ffi::OsString, path::PathBuf};
use avbroot::cli::args::{LogFormat, LogLevel};
use avbroot::cli::args::LogFormat;
use clap::{Args, Parser, Subcommand, ValueEnum};
use tracing::Level;
#[derive(Debug, Args)]
pub struct ProfileGroup {
@@ -69,8 +70,8 @@ pub struct Cli {
pub command: Command,
/// Lowest log message severity to output.
#[arg(long, global = true, value_name = "LEVEL", default_value_t)]
pub log_level: LogLevel,
#[arg(long, global = true, value_name = "LEVEL", default_value_t = Level::INFO)]
pub log_level: Level,
/// Output format for log messages.
#[arg(long, global = true, value_name = "FORMAT", default_value_t = LogFormat::Medium)]