atlas-program-log-macro

Crates.ioatlas-program-log-macro
lib.rsatlas-program-log-macro
version1.0.1
created_at2025-12-03 15:33:39.567258+00
updated_at2025-12-03 17:37:35.381148+00
descriptionMacro for atlas program log utility
homepagehttps://anza.xyz/
repositoryhttps://github.com/anza-xyz/atlas-sdk
max_upload_size
id1964280
size17,367
(atlaschainorg)

documentation

https://docs.rs/atlas-program-log-macro

README

Atlas

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 atlas_program_log::log;

log!("a simple log");

To output a formatted message:

use atlas_program_log::log;

let amount = 1_000_000_000;
log!("transfer amount: {}", amount);

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 atlas_program_log::log;

let very_long_message = "...";
log!(500, "message: {}", very_long_message);

It is possible to include a precision formatting for numeric values:

use atlas_program_log::log;

let lamports = 1_000_000_000;
log!("transfer amount (ATLAS: {:.9}", lamports);

For &str types, it is possible to specify a maximum length and a truncation strategy:

use atlas_program_log::log;

let program_name = "atlas-program";
// log message: "...program"
log!("{:<.10}", program_name);
// log message: "atlas-..."
log!("{:>.10}", program_name);

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.

#[atlas_program_log::log_cu_usage]
fn my_function() {
   // Function body
}

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

Commit count: 0

cargo fmt