Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Logging & String Formatting

Log functions

All log functions take a single format argument and use printf-style substitution (%s, %d, %i, %f, %o/%O). There is no gobj or error-code argument — that’s the C API. The JS runtime is simpler.

log_error   (format, ...args)   // red,   prefixed "ERROR"
log_warning (format, ...args)   // yellow, prefixed "WARNING"
log_info    (format, ...args)   // cyan,  prefixed "INFO"
log_debug   (format, ...args)   // silver, prefixed "DEBUG"

trace_msg   (format, ...args)   // cyan,  prefixed "MSG"
trace_json  (json, msg)         // dir-dump a JSON object

Redirecting error / warning output

By default all logs go to the browser console. You can route error and warning level messages to a single remote handler (info and debug always stay in the console):

set_remote_log_functions(remote_log_fn)   // fn(message)

String formatting

sprintf(format, ...args)   // printf-style
vsprintf(fmt, argv)        // variadic version

Format specifiers

SpecMeaning
%sstring
%d, %iinteger
%f, %e, %greal
%o, %x, %Xoctal / hex
%bbinary
%ccharacter
%jJSON-stringify
%tboolean (true/false)
%Ttype name
%vvalue (auto-detected)
%uunsigned integer