shadowsocks_rust/logging/
mod.rs

1//! Logging facilities
2
3use std::path::Path;
4
5use log::warn;
6
7use crate::config::LogConfig;
8
9mod log4rs;
10mod tracing;
11
12/// Initialize logger ([log4rs](https://crates.io/crates/log4rs), [trace4rs](https://crates.io/crates/trace4rs)) from yaml configuration file
13pub fn init_with_file<P>(path: P)
14where
15    P: AsRef<Path>,
16{
17    log4rs::init_with_file(path);
18
19    warn!(
20        "log4rs doesn't support the tracing (https://crates.io/crates/tracing) framework, 
21         so it would be removed in the future. Consider configure logging with RUST_LOG environment variable. 
22         Check more configuration detail in https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/index.html#filtering-events-with-environment-variables ."
23    );
24}
25
26/// Initialize logger with provided configuration
27pub fn init_with_config(bin_name: &str, config: &LogConfig) {
28    // log4rs::init_with_config(bin_name, config);
29    tracing::init_with_config(bin_name, config);
30}
31
32/// Init a default logger
33pub fn init_with_default(bin_name: &str) {
34    init_with_config(bin_name, &LogConfig::default());
35}