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.
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.
```rust
fn atoi(a: &str) -> Result
The detail is documented below.
The following attribute injects logging code before function is called.
```rust use logfn::logfn;
fn add(a: usize, b: usize) -> usize { a + b } ```
The resulting code will looks like
```rust fn add(a: usize, b: usize) -> usize { log::info!("executing add...");
{
a + b
}
} ```
You also be able to inject logging code after function is called.
```rust use logfn::logfn;
fn add(a: usize, b: usize) -> usize { a + b } ```
The resulting code will looks like
```rust fn add(a: usize, b: usize) -> usize { let res = (move || { a + b })();
log::info!("executed add!");
res
} ```
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.
Conditional logging is only supported in post logging for now.
```rust use logfn::logfn;
fn checkedadd(a: usize, b: usize) -> Option
We support below format patterns.
```rust
use logfn::logfn;
fn atoi(s: &str) -> Result
Async function is also supported.
```rust use logfn::logfn;
async fn add_fut(a: usize, b: usize) -> usize { a + b } ```