Crate pinocchio_log

Crate pinocchio_log 

Source
Expand description

Lightweight log utility for Solana programs.

This crate provides a Logger struct that can be used to efficiently log messages in a Solana 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 pinocchio_log::logger::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 pinocchio_log::logger::{Argument, Logger};

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

let lamports = 1_000_000_000u64;

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

Modules§

logger

Macros§

log
Companion log! macro for pinocchio-log.

Attribute Macros§

log_cu_usage
Attribute macro for instrumenting functions with compute unit logging.