mirror of
https://github.com/DefectingCat/rua-list
synced 2025-07-15 16:51:31 +00:00
Add more log layer
This commit is contained in:
71
Cargo.lock
generated
71
Cargo.lock
generated
@ -175,7 +175,7 @@ dependencies = [
|
||||
"js-sys",
|
||||
"num-integer",
|
||||
"num-traits",
|
||||
"time",
|
||||
"time 0.1.45",
|
||||
"wasm-bindgen",
|
||||
"winapi",
|
||||
]
|
||||
@ -263,6 +263,25 @@ version = "0.8.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-channel"
|
||||
version = "0.5.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-utils"
|
||||
version = "0.8.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3c063cd8cc95f5c377ed0d4b49a4b21f632396ff690e8470c29b3359b346984b"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cxx"
|
||||
version = "1.0.94"
|
||||
@ -1046,6 +1065,8 @@ dependencies = [
|
||||
"tokio",
|
||||
"tower",
|
||||
"tracing",
|
||||
"tracing-appender",
|
||||
"tracing-error",
|
||||
"tracing-subscriber",
|
||||
"wildmatch",
|
||||
]
|
||||
@ -1312,6 +1333,33 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.3.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cd0cbfecb4d19b5ea75bb31ad904eb5b9fa13f21079c3b92017ebdf4999a5890"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"serde",
|
||||
"time-core",
|
||||
"time-macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time-core"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd"
|
||||
|
||||
[[package]]
|
||||
name = "time-macros"
|
||||
version = "0.2.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fd80a657e71da814b8e5d60d3374fc6d35045062245d80224748ae522dd76f36"
|
||||
dependencies = [
|
||||
"time-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinyvec"
|
||||
version = "1.6.0"
|
||||
@ -1427,6 +1475,17 @@ dependencies = [
|
||||
"tracing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-appender"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09d48f71a791638519505cefafe162606f706c25592e4bde4d97600c0195312e"
|
||||
dependencies = [
|
||||
"crossbeam-channel",
|
||||
"time 0.3.20",
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-attributes"
|
||||
version = "0.1.24"
|
||||
@ -1448,6 +1507,16 @@ dependencies = [
|
||||
"valuable",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-error"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d686ec1c0f384b1277f097b2f279a2ecc11afe8c133c1aabf036a27cb4cd206e"
|
||||
dependencies = [
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-log"
|
||||
version = "0.1.3"
|
||||
|
@ -22,3 +22,5 @@ async-trait = "0.1.68"
|
||||
futures-util = "0.3.28"
|
||||
tracing = "0.1.37"
|
||||
tracing-subscriber = "0.3.17"
|
||||
tracing-appender = "0.2.2"
|
||||
tracing-error = "0.2.0"
|
||||
|
@ -1,10 +1,36 @@
|
||||
use crate::config::Config;
|
||||
use anyhow::Result;
|
||||
use tracing_appender::{non_blocking, rolling};
|
||||
use tracing_error::ErrorLayer;
|
||||
use tracing_subscriber::{
|
||||
filter, fmt, prelude::__tracing_subscriber_SubscriberExt, util::SubscriberInitExt, Registry,
|
||||
};
|
||||
|
||||
pub fn logger_init(config: &Config) {
|
||||
tracing_subscriber::fmt()
|
||||
.compact()
|
||||
.with_file(false)
|
||||
pub fn logger_init(config: &Config) -> Result<()> {
|
||||
let log_path = config.log_path.as_ref().expect("Can not read log path");
|
||||
|
||||
let formatting_layer = fmt::layer()
|
||||
// .pretty()
|
||||
.with_thread_ids(true)
|
||||
.with_target(false)
|
||||
.with_writer(std::io::stdout);
|
||||
|
||||
let file_appender = rolling::daily(log_path, "rua-list.log");
|
||||
let (non_blocking, _guard) = non_blocking(file_appender);
|
||||
let file_layer = fmt::layer()
|
||||
.compact()
|
||||
.with_target(false)
|
||||
.with_thread_ids(true)
|
||||
.with_writer(non_blocking);
|
||||
|
||||
let filter = filter::LevelFilter::INFO;
|
||||
|
||||
Registry::default()
|
||||
.with(filter)
|
||||
.with(ErrorLayer::default())
|
||||
.with(formatting_layer)
|
||||
.with(file_layer)
|
||||
.init();
|
||||
|
||||
Ok(())
|
||||
}
|
@ -10,6 +10,7 @@ use tower::{timeout::TimeoutLayer, ServiceBuilder};
|
||||
use crate::{
|
||||
config::Config,
|
||||
header_parser::headers_parser,
|
||||
logger::logger_init,
|
||||
middlewares::logger::logger_middleware,
|
||||
routes::messages::{match_check_get, match_check_post},
|
||||
};
|
||||
@ -28,12 +29,7 @@ mod routes;
|
||||
async fn main() -> Result<()> {
|
||||
let config = Config::build();
|
||||
|
||||
tracing_subscriber::fmt()
|
||||
.compact()
|
||||
.with_file(false)
|
||||
.with_thread_ids(true)
|
||||
.with_target(false)
|
||||
.init();
|
||||
logger_init(&config)?;
|
||||
info!("Server starting");
|
||||
|
||||
let port = if let Some(port) = config.port {
|
||||
|
Reference in New Issue
Block a user