standard logger

This commit is contained in:
mbecker20
2023-07-13 23:42:28 -04:00
parent 100f34a32b
commit 946f427c4b
8 changed files with 45 additions and 19 deletions

11
Cargo.lock generated
View File

@@ -1655,6 +1655,15 @@ version = "0.4.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "518ef76f2f87365916b142844c16d8fefd85039bc5699050210a7778ee1cd1de"
[[package]]
name = "logger"
version = "1.0.0"
dependencies = [
"anyhow",
"log",
"simple_logger",
]
[[package]]
name = "lru-cache"
version = "0.1.2"
@@ -1841,6 +1850,7 @@ dependencies = [
"hmac",
"jwt",
"log",
"logger",
"merge_config_files",
"monitor_types",
"mungos",
@@ -1885,6 +1895,7 @@ dependencies = [
"dotenv",
"envy",
"log",
"logger",
"merge_config_files",
"monitor_types",
"parse_csl",

View File

@@ -12,8 +12,9 @@ license = "GPL-3.0-or-later"
monitor_macros = { path = "lib/macros" }
monitor_types = { path = "lib/types" }
monitor_client = { path = "client/rs" }
periphery_client = { path = "lib/periphery_client" }
monitor_periphery = { path = "periphery" }
periphery_client = { path = "lib/periphery_client" }
logger = { path = "lib/logger" }
# external
tokio = { version = "1.28", features = ["full"] }
axum = { version = "0.6", features = ["ws", "json", "headers"] }

View File

@@ -15,6 +15,7 @@ path = "src/main.rs"
# local
monitor_types.workspace = true
periphery_client.workspace = true
logger.workspace = true
# external
tokio.workspace = true
tokio-util.workspace = true
@@ -48,4 +49,4 @@ merge_config_files.workspace = true
parse_csl.workspace = true
termination_signal.workspace = true
resolver_api.workspace = true
mungos.workspace = true
mungos.workspace = true

View File

@@ -9,7 +9,6 @@ use monitor_types::{
},
requests::auth::GetLoginOptionsResponse,
};
use simple_logger::SimpleLogger;
use crate::{
auth::{GithubOauthClient, GoogleOauthClient, JwtClient},
@@ -50,13 +49,7 @@ impl State {
let env = Env::load()?;
let config = CoreConfig::load(&env.config_path);
SimpleLogger::new()
.with_level(config.log_level.into())
.env()
.with_colors(true)
.with_utc_timestamps()
.init()
.context("failed to configure logger")?;
logger::init(config.log_level.into())?;
debug!("loading state");

13
lib/logger/Cargo.toml Normal file
View File

@@ -0,0 +1,13 @@
[package]
name = "logger"
version.workspace = true
edition.workspace = true
authors.workspace = true
license.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
log.workspace = true
simple_logger.workspace = true
anyhow.workspace = true

13
lib/logger/src/lib.rs Normal file
View File

@@ -0,0 +1,13 @@
use anyhow::Context;
use log::LevelFilter;
use simple_logger::SimpleLogger;
pub fn init(log_level: LevelFilter) -> anyhow::Result<()> {
SimpleLogger::new()
.with_level(log_level)
.env()
.with_colors(true)
.with_utc_timestamps()
.init()
.context("failed to configure logger")
}

View File

@@ -18,6 +18,7 @@ path = "src/main.rs"
[dependencies]
# local
monitor_types.workspace = true
logger.workspace = true
# external
tokio.workspace = true
axum.workspace = true
@@ -40,4 +41,4 @@ parse_csl.workspace = true
termination_signal.workspace = true
run_command.workspace = true
svi.workspace = true
resolver_api.workspace = true
resolver_api.workspace = true

View File

@@ -3,7 +3,6 @@ use std::{collections::HashMap, net::SocketAddr, str::FromStr, sync::Arc};
use anyhow::Context;
use clap::Parser;
use serde_json::json;
use simple_logger::SimpleLogger;
use crate::{
config::{CliArgs, Env, PeripheryConfig},
@@ -26,13 +25,7 @@ impl State {
pub async fn load() -> anyhow::Result<Arc<State>> {
let env = Env::load()?;
let args = CliArgs::parse();
SimpleLogger::new()
.with_level(args.log_level)
.env()
.with_colors(true)
.with_utc_timestamps()
.init()
.context("failed to configure logger")?;
logger::init(args.log_level)?;
let config = PeripheryConfig::load(&env, &args)?;
let state = State {
secrets: config.secrets.clone().into(),