Attribute Macro logging_timer::time

source ·
#[time]
Expand description

Instruments the function with a timer!, which logs a message at the end of function execution stating the elapsed time.

The attribute accepts two string literals as arguments. The first is the log level, valid values of which are “error”, “warn”, “info”, “debug”, “trace” or “never”. The default value is “debug”. “never” can be used to temporarily disable instrumentation of the function without deleting the attribute.

The second argument is the function name pattern. The pattern is helpful to disambiguate functions when you have many functions in the same module with the same name: new might occur many times on different structs, for example. In the pattern, “{}” will be replaced with the name of the function.

Examples: #[time] // Use default log level of Debug #[time(“info”)] // Set custom log level #[time(“info”, “FirstStruct::{}”)] // Logs “FirstStruct::new()” at Info #[time(“info”, “SecondStruct::{}”)] // Logs “SecondStruct::new()” at Info #[time(“ThirdStruct::{}”)] // Logs “ThirdStruct::new()” at Debug #[time(“never”)] // Turn off instrumentation at compile time