Crate logcall

source ·
Expand description

logcall

An attribute macro that logs the function return value.

This is a reimplementation of the log-derive crate with async-trait compatibility.

Usage

use logcall::logcall;

#[logcall("info")]
fn foo(a: usize) -> usize {
    a + 1
}

#[logcall(err = "error")]
fn bar(a: usize) -> Result<usize, usize> {
    Err(a + 1)
}

#[logcall(ok = "info", err = "error")]
fn baz(a: usize) -> Result<usize, usize> {
    Ok(a + 1)
}

fn main() {
    env_logger::builder().filter_level(log::LevelFilter::Info).init();
    foo(1);
    bar(1).ok();
    baz(1).ok();
}

// prints:
// [2023-07-22T06:55:10Z INFO  main] foo() => 2
// [2023-07-22T06:55:10Z ERROR main] bar() => Err(2)
// [2023-07-22T06:55:10Z INFO  main] baz() => Ok(2)

Attribute Macros

  • An attribute macro that logs the function return value.