2 releases
0.2.2 | Jun 17, 2024 |
---|---|
0.2.0 | Jun 3, 2024 |
#2 in #arpa
Used in arpa-node
6KB
As an attribute macro, log_function will
- Automatically log the name, input and return value of current function at debug level
before it returns by trying to recognize return stmt and inserting a
debug!
stmt. - Set the name of current function as a key in
mdc
at the beginning of the function and remove it before the function returns.
Note:
- Input and return type need to implement
Debug
. - When dealing with async function, using
#![feature(async_fn_in_trait)]
is recommended. Also this is compatible with#[async_trait]
. - To protect secrets, input and return values are ignored by default.
You can specify whether to print all values, or a subset of them with semantic literal options.
For example:
Then the log should be: {"message":"LogModel { fn_name: "show_subset_of_input_and_return_value", fn_args: ["foo: ignored", "bar: ignored", "baz: 3"], fn_return: "6" }","level":"DEBUG", "target":"show_subset_of_input_and_return_value","mdc":{"fn_name":"show_subset_of_input_and_return_value"}} with test logger.use arpa_log::*; #[log_function("show-input", "except foo bar", "show-return")] fn show_subset_of_input_and_return_value(foo: usize, bar: usize, baz: usize) -> usize { foo + bar + baz }
Note: Logging result can be different with different logger implementation.
Dependencies
~1.5MB
~38K SLoC