Hare comes with a basic built-in logger to be used to log any information you want as your program runs. We can even set the global logger to change the format of the log lines to JSON or logfmt like we illustrate in the example.
use log;
use log::logfmt;
use os;
export fn main() void = {
log::println("simple information with the built-in logger");
const rate = 23z;
log::printfln("pass in formatting values like {}", rate);
// Make a new logfmt logger and set it as the global logger. You
// will need to install a 3rd party logger such as hare-logfmt
// or create your own to change the format.
//
// Module: https://git.sr.ht/~blainsmith/hare-logfmt
const logger = logfmt::new(os::stdout);
log::setlogger(&logger);
// Now we can can pass key/value arguments and get a logfmt
// format type of log line.
log::println("http.method", "GET", "http.path", "/ping");
log::println("http.method", "POST", "http.path", "/user");
log::println("http.method", "PUT", "http.path", "/acct/98113");
};
% hare run logging.ha
4/4 tasks completed (100%)
[2025-08-09 16:30:13] simple information with the built-in logger
[2025-08-09 16:30:13] pass in formatting values like 23
ts=2025-08-09T20:30:13+0000 http.method=GET http.path=/ping
ts=2025-08-09T20:30:13+0000 http.method=POST http.path=/user
ts=2025-08-09T20:30:13+0000 http.method=PUT http.path=/acct/98113
Back to table of contents