diff --git a/Cargo.toml b/Cargo.toml index aaa34f4..ffe7c4d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "logcall" version = "0.1.4" edition = "2021" authors = ["andylokandy "] -description = "An attribute macro that logs the return value from function call." +description = "An attribute macro that logs the function return value." repository = "https://github.com/andylokandy/logfn" documentation = "https://docs.rs/logfn" categories = ["development-tools::debugging"] diff --git a/README.md b/README.md index 7496445..65d783a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # logcall -An attribute macro that logs the return value from function call. +An attribute macro that logs the function return value. This is a reimplementation of the [`log-derive`](https://crates.io/crates/log-derive) crate with [`async-trait`](https://crates.io/crates/async-trait) compatibility. diff --git a/examples/main.rs b/examples/main.rs index a02fb71..b979a5d 100644 --- a/examples/main.rs +++ b/examples/main.rs @@ -6,12 +6,12 @@ fn foo(a: usize) -> usize { } #[logcall(err = "error")] -fn bar(a: usize) -> Result { - Err(a + 1) +fn bar(a: usize) -> Result { + Err(format!("{}", a + 1)) } #[logcall(ok = "info", err = "error")] -fn baz(a: usize) -> Result { +fn baz(a: usize) -> Result { Ok(a + 1) } diff --git a/src/lib.rs b/src/lib.rs index df95ee7..4ee042a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -74,7 +74,7 @@ impl Args { } } -/// An attribute macro that logs the return values of functions. +/// An attribute macro that logs the function return value. #[proc_macro_attribute] #[proc_macro_error] pub fn logcall( @@ -270,7 +270,7 @@ fn gen_log(level: &str, fn_name: &str, return_value: &str) -> proc_macro2::Token let level: Ident = Ident::new(&level, Span::call_site()); let return_value: Ident = Ident::new(return_value, Span::call_site()); quote!( - log::#level! ("{}() => {:?}", #fn_name, #return_value) + log::#level! ("{}() => {:?}", #fn_name, &#return_value) ) }