Htrace

Crates.ioHtrace
lib.rsHtrace
version1.0.2
sourcesrc
created_at2024-08-18 14:03:26.817829
updated_at2024-10-27 12:47:33.121827
descriptionsimple tracing system
homepage
repositoryhttps://github.com/hyultis/rust_Htrace
max_upload_size
id1342639
size47,283
(hyultis)

documentation

README

HTrace

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 )

  • File : write trace into file (write a file by day or by hour, by thread name, by source file, etc)
  • CommandLine : write trace into stdout (with coloration)

list of trace level : (in order)

  • Type::DEBUG : debugging trace (for developpement) - LOWER LEVEL
  • Type::DEBUGERR : debugging trace for a error
  • Type::NORMAL : normal trace
  • Type::NOTICE : important trace for the remaining of trace
  • Type::NOTICEDERR => trace of an error, but who have been noticed to somebody (mail by example)
  • Type::WARNING => trace that need to be checked
  • Type::ERROR : trace of an error or something that blocks
  • Type::FATAL : trace who lead into panic - HIGHER LEVEL

Configuration of htrace and each module is saved into configuration dir (via Hconfig), into "Htrace.json"

Online Documentation

Master branch

Example

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.

License

Licensed under either of

at your option.

Contribution

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.

Commit count: 23

cargo fmt