Crate atlas_program_log

Crate atlas_program_log 

Source
Expand description

Lightweight log utility for Atlas programs.

This crate provides a Logger struct that can be used to efficiently log messages in a Atlas program. The Logger struct is a wrapper around a fixed-size buffer, where types that implement the Log trait can be appended to the buffer.

The Logger struct is generic over the size of the buffer, and the buffer size should be chosen based on the expected size of the log messages. When the buffer is full, the log message will be truncated. This is represented by the @ character at the end of the log message.

§Example

Creating a Logger with a buffer size of 100 bytes, and appending a string and an u64 value:

use atlas_program_log::Logger;

let mut logger = Logger::<100>::default();
logger.append("balance=");
logger.append(1_000_000_000);
logger.log();

// Clear the logger buffer.
logger.clear();

logger.append(&["Hello ", "world!"]);
logger.log();

It also support adding precision to numeric types:

use atlas_program_log::{Argument, Logger};

let mut logger = Logger::<100>::default();

let lamports = 1_000_000_000u64;

logger.append("balance (ATLAS)=");
logger.append_with_args(lamports, &[Argument::Precision(9)]);
logger.log();

Re-exports§

pub use logger::Argument;
pub use logger::Logger;

Modules§

logger

Macros§

logmacro
Companion log! macro for atlas-program-log.

Attribute Macros§

log_cu_usagemacro
Attribute macro for instrumenting functions with compute unit logging.