mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-01 10:15:31 +00:00
aquatic_ws: add logging with level configured by config file
This commit is contained in:
parent
0d4bc25ea9
commit
bc8916dce4
7 changed files with 96 additions and 36 deletions
|
|
@ -1,5 +1,8 @@
|
|||
use aquatic_ws;
|
||||
use cli_helpers;
|
||||
use anyhow::Context;
|
||||
use cli_helpers::run_app_with_cli_and_config;
|
||||
use simplelog::{ConfigBuilder, LevelFilter, TermLogger, TerminalMode, ThreadLogMode};
|
||||
|
||||
use aquatic_ws::config::{Config, LogLevel};
|
||||
|
||||
|
||||
#[global_allocator]
|
||||
|
|
@ -7,10 +10,35 @@ static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
|
|||
|
||||
|
||||
fn main(){
|
||||
// ::simple_logger::init().unwrap();
|
||||
|
||||
cli_helpers::run_app_with_cli_and_config::<aquatic_ws::config::Config>(
|
||||
run_app_with_cli_and_config::<Config>(
|
||||
"aquatic: webtorrent tracker",
|
||||
aquatic_ws::run,
|
||||
run
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
fn run(config: Config) -> anyhow::Result<()> {
|
||||
let level_filter = match config.log_level {
|
||||
LogLevel::Off => LevelFilter::Off,
|
||||
LogLevel::Error => LevelFilter::Error,
|
||||
LogLevel::Warn => LevelFilter::Warn,
|
||||
LogLevel::Info => LevelFilter::Info,
|
||||
LogLevel::Debug => LevelFilter::Debug,
|
||||
LogLevel::Trace => LevelFilter::Trace,
|
||||
};
|
||||
|
||||
let simplelog_config = ConfigBuilder::new()
|
||||
.set_time_to_local(true)
|
||||
.set_location_level(LevelFilter::Off)
|
||||
.set_thread_level(LevelFilter::Error)
|
||||
.set_thread_mode(ThreadLogMode::Both)
|
||||
.build();
|
||||
|
||||
TermLogger::init(
|
||||
level_filter,
|
||||
simplelog_config,
|
||||
TerminalMode::Stdout
|
||||
).context("Couldn't initialize logger")?;
|
||||
|
||||
aquatic_ws::run(config)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue