Skip to content
Jennifer Programming Language

log API reference

Leveled, structured logging. A log.Logger carries a minimum level (debug < info < warn < error), an output format (text / logfmt / json), and a sink; log.info(logger, message, fields) (and the sibling levels) render one record - a timestamp, the level, the message, and the caller's key/value fields - and write it, dropping records below the logger's level.

Sinks: stdout / stderr (both binaries, via io), a file (append, via fs), and an RFC 5424 syslog sink over UDP (net, so the syslog sink needs the default jennifer binary; the console / file sinks work on both). Over io / fs + json + strings + time + os (+ net for syslog).

Import with import "log.j" as log;. See the log guide for prose and examples.

Contents

NameWhat it is
atEmit a record at an explicit level (skipped if below the logger's level).
debugEmit a debug record.
errorEmit an error record.
fatalEmit a fatal record and then terminate the program with exit code 1.
infoEmit an info record.
newA logger writing to standard output.
toFileA logger appending to a file (created if missing).
toStderrA logger writing to standard error.
toSyslogA logger sending RFC 5424 records to a syslog server over UDP.
warnEmit a warn record.
withA child logger carrying persistent context fields.
Loggerstruct: A value-semantic logger configuration.

Functions

at

jennifer
log.at(
    logger as Logger,
    level as string,
    message as string,
    fields as map of string to string)

Emit a record at an explicit level (skipped if below the logger's level).

logger
the logger
level
"debug", "info", "warn", or "error"
message
the log message
fields
structured key/value fields ({} for none)
Throws Error
kind "log" on an unknown level; a positioned fs / net error on a sink failure

debug

jennifer
log.debug(
    logger as Logger,
    message as string,
    fields as map of string to string)

Emit a debug record.

logger
the logger
message
the log message
fields
structured fields ({} for none)

error

jennifer
log.error(
    logger as Logger,
    message as string,
    fields as map of string to string)

Emit an error record.

logger
the logger
message
the log message
fields
structured fields ({} for none)

fatal

jennifer
log.fatal(
    logger as Logger,
    message as string,
    fields as map of string to string)

Emit a fatal record and then terminate the program with exit code 1. The "fatal" level ranks above every other, so the record is always emitted regardless of the logger's minimum level.

logger
the logger
message
the log message
fields
structured fields ({} for none)

info

jennifer
log.info(
    logger as Logger,
    message as string,
    fields as map of string to string)

Emit an info record.

logger
the logger
message
the log message
fields
structured fields ({} for none)

new

jennifer
log.new(format as string, level as string)

A logger writing to standard output.

format
"text", "logfmt", or "json"
level
the minimum level ("debug"/"info"/"warn"/"error")
Returns Logger
the logger
Throws Error
kind "log" on an unknown format or level

toFile

jennifer
log.toFile(format as string, level as string, path as string)

A logger appending to a file (created if missing).

format
"text", "logfmt", or "json"
level
the minimum level
path
the file path
Returns Logger
the logger
Throws Error
kind "log" on an unknown format or level

toStderr

jennifer
log.toStderr(format as string, level as string)

A logger writing to standard error.

format
"text", "logfmt", or "json"
level
the minimum level
Returns Logger
the logger
Throws Error
kind "log" on an unknown format or level

toSyslog

jennifer
log.toSyslog(level as string, address as string, app as string)

A logger sending RFC 5424 records to a syslog server over UDP. Needs the default jennifer binary (net).

level
the minimum level
address
the syslog server "host:port" (e.g. "localhost:514")
app
the APP-NAME tag
Returns Logger
the logger
Throws Error
kind "log" on an unknown level

warn

jennifer
log.warn(
    logger as Logger,
    message as string,
    fields as map of string to string)

Emit a warn record.

logger
the logger
message
the log message
fields
structured fields ({} for none)

with

jennifer
log.with(logger as Logger, fields as map of string to string)

A child logger carrying persistent context fields. Every record emitted through the returned logger includes these fields, merged with any per-call fields (a per-call key of the same name wins). Composes: calling with again on the result merges the new fields on top of the carried ones. The parent logger is unchanged (value semantics).

logger
the parent logger
fields
the persistent fields to attach
Returns Logger
a new logger with the merged persistent fields

Structs

Logger

A value-semantic logger configuration. Build one with new / toStderr / toFile / toSyslog.

jennifer
def struct Logger {
    level as string,
    format as string,
    sink as string,
    target as string,
    app as string,
    fields as map of string to string
};
level
the minimum level to emit: "debug", "info", "warn", or "error"
format
the record format: "text", "logfmt", or "json" (ignored by the syslog sink)
sink
where records go: "stdout", "stderr", "file", or "syslog"
target
the file path (file sink) or "host:port" (syslog sink); "" for a console sink
app
an application / tag name (the syslog APP-NAME; "" means none)
fields
persistent context fields attached to every record (see with); {} for none