Last active
July 10, 2025 19:25
-
-
Save lukewagner/6fe7b01bba8fdbdbbc851be08496c65e to your computer and use it in GitHub Desktop.
canon log maybe??
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(component | |
(canon log (level info) (num-strings 2) (core func $basic-log)) | |
(canon log (level warn) (num-strings 2) (format 1 "at {0} I thought {1}") (core func $formatted-warning)) | |
(core module $M | |
(import "" "basic-log" (func $basic-log (param $str1-ptr i32) (param $str1-len i32) | |
(param $str2-ptr i32) (param $str2-len i32)) | |
(import "" "formatted-warning" (func $fancy-log (param $str1-ptr i32) (param $str1-len i32) | |
(param $str2.1-ptr i32) (param $str2.1-len i32) | |
(param $str2.2-ptr i32) (param $str2.2-len i32)) | |
... | |
) | |
(core instance $m (instantiate $M (with "" (instance | |
(export "basic-log" (func $basic-log)) | |
(export "formatted-warning" (func $formatted-warning)) | |
)))) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
canon log
to declare how many strings it outputs, but it nicely avoids the arbitrariness of baking in "2".canon log
(instead of having the wasm code do it itself) is that, when logging is turned off or dialed down (onlyerror
/warn
, notinfo
, etc), you don't have the wasm code wasting cycles formatting strings that are then ignored.canon get-log-level
built-in that lets you query the current log level at runtime (and avoid unnecessary formatting if not needed), I think mayyybe a useful property is that enabling/disabling logging has zero semantic effect on the execution which should help avoid Heisenbugs or "crashes when logging enabled". A key part of this is that if you pass garbagei32
pointers/lengths tocanon log
it's specified never to trap (just maybe produce garbled output or some "" message).