mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-08-24 05:59:42 -04:00
feat: log monero_rpc_pool only at >= INFO level
This commit is contained in:
parent
ec053404f7
commit
26f8147812
1 changed files with 70 additions and 5 deletions
|
@ -72,6 +72,9 @@ pub fn init(
|
|||
"asb",
|
||||
"monero_sys",
|
||||
"unstoppableswap-gui-rs",
|
||||
];
|
||||
|
||||
let INFO_LEVEL_CRATES: Vec<&str> = vec![
|
||||
"monero_rpc_pool",
|
||||
];
|
||||
|
||||
|
@ -98,7 +101,7 @@ pub fn init(
|
|||
.with_file(true)
|
||||
.with_line_number(true)
|
||||
.json()
|
||||
.with_filter(env_filter(level_filter, OUR_CRATES.clone())?);
|
||||
.with_filter(env_filter_with_info_crates(level_filter, OUR_CRATES.clone(), INFO_LEVEL_CRATES.clone())?);
|
||||
|
||||
// Layer for writing to the verbose log file
|
||||
// Crates: All crates with different levels (libp2p at INFO+, others at TRACE)
|
||||
|
@ -111,11 +114,12 @@ pub fn init(
|
|||
.with_file(true)
|
||||
.with_line_number(true)
|
||||
.json()
|
||||
.with_filter(env_filter_with_libp2p_info(
|
||||
.with_filter(env_filter_with_all_crates(
|
||||
LevelFilter::TRACE,
|
||||
OUR_CRATES.clone(),
|
||||
LIBP2P_CRATES.clone(),
|
||||
TOR_CRATES.clone(),
|
||||
INFO_LEVEL_CRATES.clone(),
|
||||
)?);
|
||||
|
||||
// Layer for writing to the terminal
|
||||
|
@ -141,23 +145,25 @@ pub fn init(
|
|||
.with_file(true)
|
||||
.with_line_number(true)
|
||||
.json()
|
||||
.with_filter(env_filter_with_libp2p_info(
|
||||
.with_filter(env_filter_with_all_crates(
|
||||
level_filter,
|
||||
OUR_CRATES.clone(),
|
||||
LIBP2P_CRATES.clone(),
|
||||
TOR_CRATES.clone(),
|
||||
INFO_LEVEL_CRATES.clone(),
|
||||
)?);
|
||||
|
||||
// If trace_stdout is true, we log all messages to the terminal
|
||||
// Otherwise, we only log the bare minimum
|
||||
let terminal_layer_env_filter = match trace_stdout {
|
||||
true => env_filter_with_libp2p_info(
|
||||
true => env_filter_with_all_crates(
|
||||
LevelFilter::TRACE,
|
||||
OUR_CRATES.clone(),
|
||||
LIBP2P_CRATES.clone(),
|
||||
TOR_CRATES.clone(),
|
||||
INFO_LEVEL_CRATES.clone(),
|
||||
)?,
|
||||
false => env_filter(level_filter, OUR_CRATES.clone())?,
|
||||
false => env_filter_with_info_crates(level_filter, OUR_CRATES.clone(), INFO_LEVEL_CRATES.clone())?,
|
||||
};
|
||||
|
||||
let final_terminal_layer = match format {
|
||||
|
@ -199,6 +205,29 @@ fn env_filter(level_filter: LevelFilter, crates: Vec<&str>) -> Result<EnvFilter>
|
|||
Ok(filter)
|
||||
}
|
||||
|
||||
/// This function controls which crate's logs actually get logged and from which level, with info-level crates at INFO level or higher.
|
||||
fn env_filter_with_info_crates(
|
||||
level_filter: LevelFilter,
|
||||
our_crates: Vec<&str>,
|
||||
info_level_crates: Vec<&str>,
|
||||
) -> Result<EnvFilter> {
|
||||
let mut filter = EnvFilter::from_default_env();
|
||||
|
||||
// Add directives for each crate in the provided list
|
||||
for crate_name in our_crates {
|
||||
filter = filter.add_directive(Directive::from_str(&format!(
|
||||
"{}={}",
|
||||
crate_name, &level_filter
|
||||
))?);
|
||||
}
|
||||
|
||||
for crate_name in info_level_crates {
|
||||
filter = filter.add_directive(Directive::from_str(&format!("{}=INFO", crate_name))?);
|
||||
}
|
||||
|
||||
Ok(filter)
|
||||
}
|
||||
|
||||
/// This function controls which crate's logs actually get logged and from which level, with libp2p crates at INFO level or higher.
|
||||
fn env_filter_with_libp2p_info(
|
||||
level_filter: LevelFilter,
|
||||
|
@ -230,6 +259,42 @@ fn env_filter_with_libp2p_info(
|
|||
Ok(filter)
|
||||
}
|
||||
|
||||
/// This function controls which crate's logs actually get logged and from which level, including all crate categories.
|
||||
fn env_filter_with_all_crates(
|
||||
level_filter: LevelFilter,
|
||||
our_crates: Vec<&str>,
|
||||
libp2p_crates: Vec<&str>,
|
||||
tor_crates: Vec<&str>,
|
||||
info_level_crates: Vec<&str>,
|
||||
) -> Result<EnvFilter> {
|
||||
let mut filter = EnvFilter::from_default_env();
|
||||
|
||||
// Add directives for each crate in the provided list
|
||||
for crate_name in our_crates {
|
||||
filter = filter.add_directive(Directive::from_str(&format!(
|
||||
"{}={}",
|
||||
crate_name, &level_filter
|
||||
))?);
|
||||
}
|
||||
|
||||
for crate_name in libp2p_crates {
|
||||
filter = filter.add_directive(Directive::from_str(&format!("{}=INFO", crate_name))?);
|
||||
}
|
||||
|
||||
for crate_name in tor_crates {
|
||||
filter = filter.add_directive(Directive::from_str(&format!(
|
||||
"{}={}",
|
||||
crate_name, &level_filter
|
||||
))?);
|
||||
}
|
||||
|
||||
for crate_name in info_level_crates {
|
||||
filter = filter.add_directive(Directive::from_str(&format!("{}=INFO", crate_name))?);
|
||||
}
|
||||
|
||||
Ok(filter)
|
||||
}
|
||||
|
||||
/// A writer that forwards tracing log messages to the tauri guest.
|
||||
#[derive(Clone)]
|
||||
pub struct TauriWriter {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue