Crates.io | malogany |
lib.rs | malogany |
version | 0.2.0 |
source | src |
created_at | 2021-12-23 13:37:48.168573 |
updated_at | 2021-12-24 08:14:47.03045 |
description | Simple tree/hierarchical logging library |
homepage | https://github.com/zoeyfyi/malogany |
repository | https://github.com/zoeyfyi/malogany |
max_upload_size | |
id | 502251 |
size | 106,994 |
Simple tree/hierarchical logging library
(Tree > Mahogany) + Logging => Malogany
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.
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
.