2 unstable releases

0.2.0 Dec 24, 2021
0.1.0 Dec 23, 2021

#497 in Debugging

MIT license

93KB
146 lines

Malogany

Sample of Malogany's output
Simple tree/hierarchical logging library
(Tree > Mahogany) + Logging => Malogany

Usage

Add the following to your Cargo.toml

[dependencies]
log = "0.4"
malogany = "0.1"

Initalize Malogany with the max log level

malogany::init(Level::Trace).unwrap();

For normal messages, use the info!, warn!, error! and debug! macros from the log crate. To create a branch, use enter_branch and exit_branch:

malogany::enter_branch("ident");

// any log messages will be nested within the ident branch
// you can keep nesting with `enter_branch`/`exit_branch`

malogany::exit_branch();

Branches are only rendered in debug builds for performance reasons. Future versions of this crate will make this customizable.

In version 0.2 you can use scopeguard to automatically exit the branch when the guard returned by enter_branch_scoped falls out of scope. To enable this feature, add the following to your Cargo.toml:

malogany = { version = "0.1" , features = ["scopeguard"] }

Then use malogany::enter_branch_scoped instead of malogany::enter_branch.

{
  // behaves the same as enter_branch
  let _guard = malogany::enter_branch_scoped("branch");

  // any log messages will be nested within the branch as expected

  // at the end of this block, _guard will be dropped which automatically calls `malogany::exit_branch()` 
}

Note that the guard variable is very important, it cannot be removed. See scopeguard's docs for more information.

Example

The screenshot above is the output of example/basic.rs. Try it for yourself with cargo run --example basic. For an example of using scopeguard, try cargo run --all-features --example scoped.

Dependencies

~170–415KB