logfn
This crate provides the logfn attribute macro for inserting logging code into your function.
This is heavily inspired by elichai's log-derive crate.
Currently we support 2 types of logging.
- Pre logging
- Post logging
And we have a plan to add Time logging and Count logging type.
Each logfn attribute injects a single logging code. You can put as many logfn as you want.
# use logfn;
# use ParseIntError;
The detail is documented below.
Pre logging
The following attribute injects logging code before function is called.
use logfn;
The resulting code will looks like
Post logging
You also be able to inject logging code after function is called.
use logfn;
The resulting code will looks like
Conditional logging
You can configure the condition on which logging code is fired.
To do that, please add if argument with a path to the function which takes reference to
returned value and returns true when you want to fire the logging code.
Note
Conditional logging is only supported in post logging for now.
use logfn;
Message formatting
We support below format patterns.
- "{fn}" interpolates function name
- "{ret:?}" or "{ret}" interpolates returned value
# use ParseIntError;
use logfn;
Async function
Async function is also supported.
use logfn;
async