log
The log module provides a simple interface for application logging. The logger interface provides an abstraction that users may implement for custom logging logic. We provide a simple logger implementation that prefixes each line with the current timestamp; to initialize such a logger see new.
A global logger is also provided for simple applications to use, global, which is an instance of the standard logger that writes to os::stderr by default. The user may configure a new global logger via setlogger.
Index
Types
type logger = struct {
println: *fn(logger: *logger, fields: fmt::formattable...) void,
printfln: *fn(logger: *logger, fmt: str, fields: fmt::field...) void,
};
type stdlogger = struct {
logger,
sink: io::handle,
};
Globals
const default: *logger;
let global: *logger;
const silent: *logger;
Functions
fn fatal(fields: fmt::formattable...) never;
fn fatalf(fmt: str, fields: fmt::field...) never;
fn lfatal(log: *logger, fields: fmt::formattable...) never;
fn lfatalf(log: *logger, fmt: str, fields: fmt::field...) never;
fn lprintfln(log: *logger, fmt: str, fields: fmt::field...) void;
fn lprintln(log: *logger, fields: fmt::formattable...) void;
fn new(sink: io::handle) stdlogger;
fn printfln(fmt: str, fields: fmt::field...) void;
fn println(fields: fmt::formattable...) void;
fn setlogger(log: *logger) void;
Types
type logger
type logger = struct {
println: *fn(logger: *logger, fields: fmt::formattable...) void,
printfln: *fn(logger: *logger, fmt: str, fields: fmt::field...) void,
};
Interface for implementing a logger.
type stdlogger
Show undocumented member
type stdlogger = struct {
logger,
sink: io::handle,
};
Globals
let default
const default: *logger;
Default logger that writes to os::stderr.
let global
let global: *logger;
The global logger instance.
let silent
const silent: *logger;
A logger that does not print any messages.
Functions
fn fatal
fn fatal(fields: fmt::formattable...) never;
Prints data to the global log with new line, then terminates the process.
fn fatalf
fn fatalf(fmt: str, fields: fmt::field...) never;
Formats and prints data to the global log with new line, then terminates the process.
fn lfatal
fn lfatal(log: *logger, fields: fmt::formattable...) never;
Prints data to the log with a newline, then terminates the process.
fn lfatalf
fn lfatalf(log: *logger, fmt: str, fields: fmt::field...) never;
Formats and prints data to the log with new line, then terminates the process.
fn lprintfln
fn lprintfln(log: *logger, fmt: str, fields: fmt::field...) void;
Formats and prints data to the log, with a newline.
fn lprintln
fn lprintln(log: *logger, fields: fmt::formattable...) void;
Prints data to the log, with a newline.
fn new
fn new(sink: io::handle) stdlogger;
Creates a new standard logger.
fn printfln
fn printfln(fmt: str, fields: fmt::field...) void;
Formats and prints data to the global log, with a newline.
fn println
fn println(fields: fmt::formattable...) void;
Prints data to the global log, with a newline.
fn setlogger
fn setlogger(log: *logger) void;
Sets the global logger instance to the provided logger.