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;
type stdlogger;
Globals
let default: *logger;
let silent: *logger;
Functions
fn fatal(fmt::formattable...) void;
fn fatalf(str, fmt::field...) void;
fn lfatal(*logger, fmt::formattable...) void;
fn lfatalf(*logger, str, fmt::field...) void;
fn lprintfln(*logger, str, fmt::field...) void;
fn lprintln(*logger, fmt::formattable...) void;
fn new(io::handle) stdlogger;
fn printfln(str, fmt::field...) void;
fn println(fmt::formattable...) void;
fn setlogger(*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 silent
const silent: *logger;
A logger that does not print any messages.
Functions
fn fatal
@noreturn fn fatal(fields: fmt::formattable...) void;
Prints data to the global log with new line, then terminates the process.
fn fatalf
@noreturn fn fatalf(fmt: str, fields: fmt::field...) void;
Formats and prints data to the global log with new line, then terminates the
process.
fn lfatal
@noreturn fn lfatal(log: *logger, fields: fmt::formattable...) void;
Prints data to the log with a newline, then terminates the process.
fn lfatalf
@noreturn fn lfatalf(log: *logger, fmt: str, fields: fmt::field...) void;
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.