atlas-program-log-macro
Companion log! macro for atlas-program-log. The macro automates the creation of a Logger object to log a message and supports a subset of the format! syntax. The format string is parsed at compile time and generates the calls to a Logger object to with the corresponding formatted message.
There is also a helper log_cu_usage! macro which can be used to instrument functions with compute unit logging.
Usage
log!
The macro works very similar to atlas-program msg! macro.
To output a simple message (static &str):
use log;
log!;
To output a formatted message:
use log;
let amount = 1_000_000_000;
log!;
Since a Logger size is statically determined, messages are limited to 200 length by default. When logging larger messages, it is possible to increase the logger buffer size:
use log;
let very_long_message = "...";
log!;
It is possible to include a precision formatting for numeric values:
use log;
let lamports = 1_000_000_000;
log!;
For &str types, it is possible to specify a maximum length and a truncation strategy:
use log;
let program_name = "atlas-program";
// log message: "...program"
log!;
// log message: "atlas-..."
log!;
log_cu_usage!
This macro wraps the decorated function with additional logging statements that print the function name and the number of compute units used before and after the function execution.
The generated output will be:
Program log: Function `my_function` consumed 36 compute units
License
The code is licensed under the Apache License Version 2.0