arpa_log/lib.rs
1//! As an attribute macro, log_function will
2//! 1. Automatically log the name, input and return value of current function at debug level
3//! before it returns by trying to recognize return stmt and inserting a `debug!` stmt.
4//! 2. Set the name of current function as a key in `mdc` at the beginning of the function and
5//! remove it before the function returns.
6//!
7//! Note:
8//! 1. Input and return type need to implement `Debug`.
9//! 2. When dealing with async function, using `#![feature(async_fn_in_trait)]` is recommended.
10//! Also this is compatible with `#[async_trait]`.
11//! 3. To protect secrets, input and return values are ignored by default.
12//! You can specify whether to print all values, or a subset of them with semantic literal options.
13//! For example:
14//! ```
15//! use arpa_log::*;
16//!
17//! #[log_function("show-input", "except foo bar", "show-return")]
18//! fn show_subset_of_input_and_return_value(foo: usize, bar: usize, baz: usize) -> usize {
19//! foo + bar + baz
20//! }
21//! ```
22//! Then the log should be: {"message":"LogModel { fn_name: \"show_subset_of_input_and_return_value\",
23//! fn_args: [\"foo: ignored\", \"bar: ignored\", \"baz: 3\"], fn_return: \"6\" }","level":"DEBUG",
24//! "target":"show_subset_of_input_and_return_value","mdc":{"fn_name":"show_subset_of_input_and_return_value"}}
25//! with test logger.
26//!
27//! Note: Logging result can be different with different logger implementation.
28
29pub use arpa_log_impl::*;
30pub use log::debug;
31pub use log_mdc;
32
33#[derive(Debug)]
34pub struct LogModel<'a> {
35 pub fn_name: &'a str,
36 pub fn_args: &'a [&'a str],
37 pub fn_return: &'a str,
38}