Crates.io | Htrace |
lib.rs | Htrace |
version | 1.0.2 |
source | src |
created_at | 2024-08-18 14:03:26.817829 |
updated_at | 2024-10-27 12:47:33.121827 |
description | simple tracing system |
homepage | |
repository | https://github.com/hyultis/rust_Htrace |
max_upload_size | |
id | 1342639 |
size | 47,283 |
A tracing class.
HTrace, aim to generate simple, human-readable, tracing lines into different modules. Usable for realtime application, script, api or website. Work as a service (singleton)
Htrace contains 2 default modules : (you can write your own module easily )
list of trace level : (in order)
Configuration of htrace and each module is saved into configuration dir (via Hconfig), into "Htrace.json"
Note: the crate is using Hconfig for configuration
fn main()
{
// configuration path, the directory need to be existing or created before continuing
HConfigManager::singleton().setConfPath("./config");
// Adding modules into Htrace, default configuration is used if there is no configuration file, or missing part.
HTracer::appendModule("cmd", CommandLine::CommandLine::new(CommandLineConfig::default())).expect("Cannot append module");
HTracer::appendModule("file", File::File::new(FileConfig::default())).expect("Cannot append module");
// settings
HTracer::threadSetName("testThreadName"); // default thread, can be call for each thread
HTracer::minlvl_default(Type::DEBUG);
// simple trace of variable
let string_test = "machin".to_string();
HTrace!(string_test);
// trace with auto format
HTrace!("test macro {}",87);
// trace with return line
HTrace!("test macro\nlmsdkhfsldf\nmsdf\nhjsdf");
// trace different level (ERROR level and above show backtrace)
HTrace!((Type::NOTICE) "my trace");
HTrace!((Type::ERROR) 21);
HTrace!((Type::ERROR) "test macro {}",87);
// macro for consuming Result, and tracing the error, default to ERROR (ERROR level and above show backtrace)
let testerror = std::fs::File::open(Path::new("idontexist.muahahah"));
HTraceError!((Type::FATAL) "File error is : {}",testerror);
HTracer::drop(); // cannot be put in "Drop" because of OnceCell
}
you can also check tests.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.