pinocchio-log-macro

Crates.iopinocchio-log-macro
lib.rspinocchio-log-macro
version
sourcesrc
created_at2024-11-10 12:37:40.317587+00
updated_at2025-03-19 00:27:58.615317+00
descriptionMacro for pinocchio log utility
homepage
repositoryhttps://github.com/anza-xyz/pinocchio
max_upload_size
id1442858
Cargo.toml error:TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
(anza-team)

documentation

README

pinocchio-log-macro

pinocchio-log-macro

Companion log! macro for pinocchio-log.

Overview

The macro automates the creation of a Logger object to log a message. It support a subset of the format! syntax. The macro parses the format string at compile time and generates the calls to a Logger object to generate the corresponding formatted message.

Usage

The macro works very similar to solana-program msg! macro.

To output a simple message (static &str):

use pinocchio_log::log

log!("a simple log");

To output a formatted message:

use pinocchio_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 pinocchio_log::log

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

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

use pinocchio_log::log

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

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

use pinocchio_log::log

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

License

The code is licensed under the Apache License Version 2.0

Commit count: 0

cargo fmt