malogany

Crates.iomalogany
lib.rsmalogany
version0.2.0
sourcesrc
created_at2021-12-23 13:37:48.168573
updated_at2021-12-24 08:14:47.03045
descriptionSimple tree/hierarchical logging library
homepagehttps://github.com/zoeyfyi/malogany
repositoryhttps://github.com/zoeyfyi/malogany
max_upload_size
id502251
size106,994
Zoey Sheffield (zoeyfyi)

documentation

README

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.

Commit count: 6

cargo fmt