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
mdcat 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 *;
Note: Logging result can be different with different logger implementation.