Skip to content

program-log: Add new crate#356

Merged
febo merged 47 commits intoanza-xyz:masterfrom
febo:solana-program-log
Oct 9, 2025
Merged

program-log: Add new crate#356
febo merged 47 commits intoanza-xyz:masterfrom
febo:solana-program-log

Conversation

@febo
Copy link
Copy Markdown
Contributor

@febo febo commented Oct 8, 2025

Problem

Currently, logging messages that require formatting are a bit heavy on the CU consumption. For example, a simple msg!("lamports={}", lamports) log can take ~627 CUs.

Solution

Create a lightweight log! macro that improves CU consumption.

Below is a sample of the improvements observed when formatting log messages, measured in terms of compute units (CU):

Ouput message log! msg! Improvement (%)
"Hello world!" 104 104 -
"lamports={}" + u64 286 625 (+339) 55%
"{}" + [&str; 2] 119 1610 (+1491) 93%
"lamports={}" + i64 299 659 (+360) 55%
"{}" + [u8; 32] (address bytes) 2783 8397 (+5614) 67%
"lamports={:.9}" + u64 438 2656 (+2218)* 84%

* For msg!, the value is logged as a f64 otherwise the precision formatting is ignored.

febo and others added 30 commits October 8, 2025 03:03
* Add log standalone crate

* Refactored

* Fix return value

* Remove additional crate

* Tidy up

* Use memcpy

* Improve digit formatting

* Improve slice formatting

* Improve comments

* Add readme

* Update README.md

* Update README.md

* Remove doctests

* Use workspace values
* Add precision argument

* Add std feature

* Add std feature cfg

* Add precision to solana target

* Add precision support for signed types

* Add inline

* Update docs

* Fix slice offset

* Fix delta for signed values

* Fix doc tests
* Add precision formatting

* Remove lazy lock

* Add precision formatting details

* Update banner image

* Add subtitle
* Bump version

* Inline never

* Add precision support to str

* Add trucated attributes
* Add truncate format parsing

* Add formatting options
* Fix typo

* Add support for usize and isize

* Improve sign conversion

* Add tests

* Simplify isize handling
* Avoid duplicate crates

* Fix vulnerable package
* Update README.md

* Update README.md

* Update README.md
* [wip]: Address review comments

* [wip]: Fix pointer reference

* [wip]: Add logger buffer size tests

* Remove unused

* More logger tests

* Rename program to cpi

* Remove dynamic allocation

* Fixed signed tests

* Fix review comments

* Fix unsigned test case

* Add is_owner_by helper
* Update readme

* Add docs

* Fix link
* Tweaks

* Add bool support
* fix: make sol_log_ call public

* fix: logger formatting
* feat: add compute_fn proc_macro_attribute

* WIP: use sol_remaining_compute_units syscall for calc

* docs: actualize docs and add introspection cost comment

* refactor: add static-syscall, remove dep on pinocchio from log, rename compute_fn -> log_cu_usage

* fix: correct comment

* fix: ci format step
* Calculate max digits

* Remove second const

Co-authored-by: Jon C <me@jonc.dev>

---------

Co-authored-by: Jon C <me@jonc.dev>
febo and others added 11 commits October 8, 2025 03:03
* Add invoke instruction helper

* Typos

* Remove new helpers

* Remove unused

* Address review comments

* Tweak inline attributes

* Use invoke signed unchecked

* Refactor inline

* Renamed to with_bounds

* Update docs

* Revert change

* Add constant length check

* Add spellcheck step

* Tweak action

* Fix typos

* More fixes

* Yet more fixes

* Fixes

* Add j1 option

* More and more fixes

* Add missing acronym

* Fix merge

* Fix spelling

* Fix spelling
* Add precision cap

* Add tests

* Refactor precision logic

* Fix miri warning

* Avoid duplication

* Add missing syscall

* More tests

* Fix truncate logic

* Fix review comments
Updated README to correct links and improve formatting.
@febo febo force-pushed the solana-program-log branch from ab0b1fe to 94e75bb Compare October 8, 2025 02:03
@febo febo marked this pull request as draft October 8, 2025 02:08
@febo febo force-pushed the solana-program-log branch from 94e75bb to ac253fd Compare October 8, 2025 09:18
@febo febo marked this pull request as ready for review October 8, 2025 09:36
@febo febo requested a review from joncinque October 8, 2025 09:36
Copy link
Copy Markdown
Collaborator

@joncinque joncinque left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! I'm assuming the code is the same as in pinocchio, so I focused on integrating this in the repo

Comment thread Cargo.toml Outdated
Comment thread program-log/README.md Outdated
Comment thread program-log-macro/Cargo.toml
Comment thread program-log/macro/README.md Outdated
Comment thread program-log/crate/README.md Outdated
Comment thread program-log/macro/Cargo.toml Outdated
@febo
Copy link
Copy Markdown
Contributor Author

febo commented Oct 8, 2025

Looks great! I'm assuming the code is the same as in pinocchio, so I focused on integrating this in the repo

Yes, the code is the same.

@febo febo requested a review from joncinque October 8, 2025 22:16
Copy link
Copy Markdown
Collaborator

@joncinque joncinque left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@febo febo merged commit c14ab07 into anza-xyz:master Oct 9, 2025
26 checks passed
@febo febo deleted the solana-program-log branch October 9, 2025 00:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants