MCPcopy Create free account
hub / github.com/Recordscript/recordscript / init_log

Function init_log

libs/hbb_common/src/lib.rs:352–395  ·  view source on GitHub ↗
(_is_async: bool, _name: &str)

Source from the content-addressed store, hash-verified

350}
351
352pub fn init_log(_is_async: bool, _name: &str) -> Option<flexi_logger::LoggerHandle> {
353 static INIT: std::sync::Once = std::sync::Once::new();
354 #[allow(unused_mut)]
355 let mut logger_holder: Option<flexi_logger::LoggerHandle> = None;
356 INIT.call_once(|| {
357 #[cfg(debug_assertions)]
358 {
359 use env_logger::*;
360 init_from_env(Env::default().filter_or(DEFAULT_FILTER_ENV, "info"));
361 }
362 #[cfg(not(debug_assertions))]
363 {
364 // https://docs.rs/flexi_logger/latest/flexi_logger/error_info/index.html#write
365 // though async logger more efficient, but it also causes more problems, disable it for now
366 let mut path = config::Config::log_path();
367 #[cfg(target_os = "android")]
368 if !config::Config::get_home().exists() {
369 return;
370 }
371 if !_name.is_empty() {
372 path.push(_name);
373 }
374 use flexi_logger::*;
375 if let Ok(x) = Logger::try_with_env_or_str("debug") {
376 logger_holder = x
377 .log_to_file(FileSpec::default().directory(path))
378 .write_mode(if _is_async {
379 WriteMode::Async
380 } else {
381 WriteMode::Direct
382 })
383 .format(opt_format)
384 .rotate(
385 Criterion::Age(Age::Day),
386 Naming::Timestamps,
387 Cleanup::KeepLogFiles(6),
388 )
389 .start()
390 .ok();
391 }
392 }
393 });
394 logger_holder
395}
396
397#[cfg(test)]
398mod test {

Callers

nothing calls this directly

Calls 4

existsMethod · 0.80
is_emptyMethod · 0.80
startMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected