Expand description
Lightweight log utility for Solana programs.
Logging is the main mechanism for getting debugging information out of running Solana programs, and there are several functions available for doing so efficiently, depending on the type of data being logged.
This crate provides a Logger struct and a collection of helper functions that
can be used to efficiently log messages in a Solana program.
The Logger struct is a wrapper around a fixed-size buffer. Types that
implement the Log trait can be appended to this buffer. The struct is
generic over the buffer size, which should be chosen based on the expected
size of the log messages. When the buffer becomes full, the log message is
truncated, indicated by an @ character at the end of the message.
§Example
Creating a Logger with a buffer size of 100 bytes, and appending a string and an
u64 value:
use solana_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 solana_program_log::{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();Re-exports§
Modules§
Macros§
- log
macro - Companion
log!macro forsolana-program-log.
Functions§
- log
- Print a string to the log.
- log_64
- Print 64-bit values represented as hexadecimal to the log.
- log_
compute_ units - Print the remaining compute units available to the program.
- log_
data - Print some slices as
base64.
Attribute Macros§
- log_
cu_ usage macro - Attribute macro for instrumenting functions with compute unit logging.