#![allow(unused_parens)]
use std::fs;
use std::path::Path;
use Htrace::components::context::Context;
use Htrace::components::level::Level;
#[cfg(any(feature = "tracing_consumer",feature = "log_consumer"))]
use Htrace::crates::bridge::HtraceBridge;
use Htrace::{HTrace, HTraceError, Spaned};
use Htrace::htracer::HTracer;
use Htrace::modules::{command_line, file};
use Htrace::modules::command_line_config::CommandLineConfig;
use Htrace::modules::file_config::FileConfig;
#[test]
fn trace()
{
let _ = fs::remove_dir_all("./traces");
let mut default_command_config = CommandLineConfig::default();
default_command_config.lineFormat =
"{time} {lvl} ({thread:>, }{context:>, }{file}:l{line}) : {msg}".to_string();
let mut global_context = Context::default();
global_context.module_add(
"cmd",
command_line::CommandLine::new(default_command_config),
);
global_context.module_add("file", file::File::new(FileConfig::default()));
global_context.level_setMin(Some(Level::DEBUG));
#[cfg(all(not(feature = "tracing_consumer"),not(feature = "log_consumer")))]
HTracer::globalContext_set(global_context);
#[cfg(any(feature = "tracing_consumer",feature = "log_consumer"))]
HTracer::globalContext_set(global_context, HtraceBridge::default());
let string_test = "machin".to_string();
HTrace!(string_test);
{
let mut local_context = Context::default();
local_context.name_set("span lvl 1");
Spaned!(local_context);
HTrace!("test inside span 1");
{
Spaned!("span lvl 2");
HTrace!("test inside span 2");
}
HTrace!("test inside span 1");
}
HTrace!("test macro {}", 87);
HTrace!((Level::DEBUG) "my debug");
HTrace!((Level::NOTICE) "my trace");
HTrace!((Level::ERROR) 21);
HTrace!((Level::FATAL) "test macro {}",87);
let testerror = std::fs::File::open(Path::new("idontexist.muahahah"));
HTraceError!("File error is : {}", testerror);
HTracer::drop();
}