log-derive
A Rust macro to part of the log facade that auto generates loggings for functions output.
Usage
Add this to your Cargo.toml
:
[]
= "0.3"
= "0.4"
and for Rust Edition 2015 add this to your crate root:
extern crate log_derive;
extern crate log;
In Rust Edition 2018 you can simply do:
use logfn;
After that all you need is to add the according macro above a function that,
either returns an output or receive an input that implements the Debug
trait.
Examples
Output
The output of the fibonacci example:
14:55:41 [INFO] fibonacci() -> 1
14:55:41 [INFO] fibonacci() -> 1
14:55:41 [INFO] fibonacci() -> 2
14:55:41 [INFO] fibonacci() -> 1
14:55:41 [INFO] fibonacci() -> 3
14:55:41 [INFO] fibonacci() -> 1
14:55:41 [INFO] fibonacci() -> 1
14:55:41 [INFO] fibonacci() -> 2
14:55:41 [INFO] fibonacci() -> 5
14:55:41 [INFO] fibonacci() -> 1
14:55:41 [INFO] fibonacci() -> 1
14:55:41 [INFO] fibonacci() -> 2
14:55:41 [INFO] fibonacci() -> 1
14:55:41 [INFO] fibonacci() -> 3
14:55:41 [INFO] fibonacci() -> 8
If you expand the output of the #[logfn]
macro the resulting code will look something like this:
If the function returns a Result
it will match through it to split between the Ok
LogLevel and the Err
LogLevel
The expansion of the #[logfn_inputs]
macro will look something like this:
Of course the log!
macro will be expanded too and it will be a bit more messy.