Add --verbose flag
This commit is contained in:
parent
f9533d8119
commit
2f7234189b
3 changed files with 16 additions and 5 deletions
|
|
@ -3,7 +3,7 @@ use std::vec;
|
|||
|
||||
use async_trait::async_trait;
|
||||
use crossterm::style::{ContentStyle, Stylize};
|
||||
use log::{Level, Log};
|
||||
use log::{Level, LevelFilter, Log};
|
||||
use parking_lot::Mutex;
|
||||
use time::OffsetDateTime;
|
||||
use tokio::sync::mpsc;
|
||||
|
|
@ -212,7 +212,7 @@ impl Log for Logger {
|
|||
}
|
||||
|
||||
impl Logger {
|
||||
pub fn init(level: Level) -> (Self, LoggerGuard, mpsc::UnboundedReceiver<()>) {
|
||||
pub fn init(verbose: bool) -> (Self, LoggerGuard, mpsc::UnboundedReceiver<()>) {
|
||||
let (event_tx, event_rx) = mpsc::unbounded_channel();
|
||||
let logger = Self {
|
||||
event_tx,
|
||||
|
|
@ -222,8 +222,13 @@ impl Logger {
|
|||
messages: logger.messages.clone(),
|
||||
};
|
||||
|
||||
log::set_max_level(if verbose {
|
||||
LevelFilter::Debug
|
||||
} else {
|
||||
LevelFilter::Info
|
||||
});
|
||||
|
||||
log::set_boxed_logger(Box::new(logger.clone())).expect("logger already set");
|
||||
log::set_max_level(level.to_level_filter());
|
||||
|
||||
(logger, guard, event_rx)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,6 +57,10 @@ impl Default for Command {
|
|||
#[derive(Debug, clap::Parser)]
|
||||
#[command(version)]
|
||||
struct Args {
|
||||
/// Show more detailed log messages.
|
||||
#[arg(long, short)]
|
||||
verbose: bool,
|
||||
|
||||
/// Path to the config file.
|
||||
///
|
||||
/// Relative paths are interpreted relative to the current directory.
|
||||
|
|
@ -114,9 +118,8 @@ fn set_offline(config: &mut Config, args_offline: bool) {
|
|||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
let (logger, logger_guard, logger_rx) = Logger::init(log::Level::Debug);
|
||||
|
||||
let args = Args::parse();
|
||||
let (logger, logger_guard, logger_rx) = Logger::init(args.verbose);
|
||||
let dirs = ProjectDirs::from("de", "plugh", "cove").expect("unable to determine directories");
|
||||
|
||||
let config_path = args
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue