dont show module when logging from python

This commit is contained in:
Christoph J. Scherr 2023-07-09 20:28:49 +02:00
parent 6e7e2c9190
commit 85e0d5e2a7
Signed by: PlexSheep
GPG Key ID: 25B4ACF7D88186CC
3 changed files with 10 additions and 4 deletions

View File

@ -47,6 +47,7 @@ pub fn main() {
// set up our logger to use the given verbosity // set up our logger to use the given verbosity
env_logger::Builder::new() env_logger::Builder::new()
.filter_module("libpt", cli.verbose.log_level_filter()) .filter_module("libpt", cli.verbose.log_level_filter())
.format_target(false)
.init(); .init();
} }
else { else {

View File

@ -82,7 +82,11 @@ impl Logger {
/// ## initializes the logger to log to a target /// ## initializes the logger to log to a target
/// ///
/// Will enable the logger to be used. /// Will enable the logger to be used.
pub fn init_specialized(test: bool, color: bool, target: Target) { pub fn init_specialized(show_module: bool, test: bool, color: bool, target: Option<Target>) {
let target = match target {
Some(t) => t,
None => Target::Stdout,
};
// only init if no init has been performed yet // only init if no init has been performed yet
if INITIALIZED.load(Ordering::Relaxed) { if INITIALIZED.load(Ordering::Relaxed) {
eprintln!("trying to reinitialize the logger, ignoring"); eprintln!("trying to reinitialize the logger, ignoring");
@ -97,6 +101,7 @@ impl Logger {
} else { } else {
WriteStyle::Never WriteStyle::Never
}) })
.format_target(show_module)
.try_init(); .try_init();
if res.is_err() { if res.is_err() {
eprintln!("could not init logger: {}", res.unwrap_err()); eprintln!("could not init logger: {}", res.unwrap_err());
@ -155,13 +160,13 @@ impl Logger {
#[pyo3(name = "init")] #[pyo3(name = "init")]
#[staticmethod] #[staticmethod]
pub fn py_init() { pub fn py_init() {
Self::init() Self::init_specialized(false, false, true, None)
} }
/// ## Python version of [`init_specialized()`](Logger::init_specialized) /// ## Python version of [`init_specialized()`](Logger::init_specialized)
#[pyo3(name = "init_specialized")] #[pyo3(name = "init_specialized")]
#[staticmethod] #[staticmethod]
pub fn py_init_specialized(color: bool) { pub fn py_init_specialized(color: bool) {
Self::init_specialized(false, color, Target::Stdout) Self::init_specialized(false, false, color, None)
} }
/// ## Python version of [`error()`](Logger::error) /// ## Python version of [`error()`](Logger::error)
#[pyo3(name = "error")] #[pyo3(name = "error")]

View File

@ -14,7 +14,7 @@ use regex::Regex;
fn setup() { fn setup() {
// we don't want to log messages during our tests! // we don't want to log messages during our tests!
std::env::set_var(LOGGER_ENV_KEY, "Trace"); std::env::set_var(LOGGER_ENV_KEY, "Trace");
Logger::init_specialized(false, false, env_logger::Target::Stdout); Logger::init_specialized(true, false, false, None);
println!() println!()
} }