mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 17:55:36 +00:00
init logger in aquatic_cli_helpers crate
This commit is contained in:
parent
427c0bc7c3
commit
8d58f8bb70
15 changed files with 113 additions and 119 deletions
|
|
@ -31,7 +31,6 @@ privdrop = "0.3"
|
|||
rand = { version = "0.7", features = ["small_rng"] }
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
socket2 = { version = "0.3", features = ["reuseport"] }
|
||||
simplelog = "0.8"
|
||||
tungstenite = "0.11"
|
||||
|
||||
[dev-dependencies]
|
||||
|
|
|
|||
|
|
@ -1,8 +1,5 @@
|
|||
use anyhow::Context;
|
||||
use aquatic_cli_helpers::run_app_with_cli_and_config;
|
||||
use simplelog::{ConfigBuilder, LevelFilter, TermLogger, TerminalMode};
|
||||
|
||||
use aquatic_ws::config::{Config, LogLevel};
|
||||
use aquatic_ws::config::Config;
|
||||
|
||||
|
||||
#[global_allocator]
|
||||
|
|
@ -12,32 +9,6 @@ static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
|
|||
fn main(){
|
||||
run_app_with_cli_and_config::<Config>(
|
||||
"aquatic: webtorrent tracker",
|
||||
run
|
||||
aquatic_ws::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,
|
||||
};
|
||||
|
||||
// Note: logger doesn't seem to pick up thread names. Not a huge loss.
|
||||
let simplelog_config = ConfigBuilder::new()
|
||||
.set_time_to_local(true)
|
||||
.set_location_level(LevelFilter::Off)
|
||||
.build();
|
||||
|
||||
TermLogger::init(
|
||||
level_filter,
|
||||
simplelog_config,
|
||||
TerminalMode::Stderr
|
||||
).context("Couldn't initialize logger")?;
|
||||
|
||||
aquatic_ws::run(config)
|
||||
}
|
||||
|
|
@ -2,24 +2,7 @@ use std::net::SocketAddr;
|
|||
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum LogLevel {
|
||||
Off,
|
||||
Error,
|
||||
Warn,
|
||||
Info,
|
||||
Debug,
|
||||
Trace
|
||||
}
|
||||
|
||||
|
||||
impl Default for LogLevel {
|
||||
fn default() -> Self {
|
||||
Self::Error
|
||||
}
|
||||
}
|
||||
use aquatic_cli_helpers::LogLevel;
|
||||
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
|
|
@ -38,6 +21,13 @@ pub struct Config {
|
|||
}
|
||||
|
||||
|
||||
impl aquatic_cli_helpers::Config for Config {
|
||||
fn get_log_level(&self) -> Option<LogLevel> {
|
||||
Some(self.log_level.clone())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(default)]
|
||||
pub struct NetworkConfig {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue