Skip to content


boxes and glue uses the slog package for structured logging. Until the slog package is part of Go's standard library, is used. Hopefully the standard library will have identical syntax and semantics.

Enable logging#

boxes and glue starts with logging disabled. It uses the bag.Logger as a logger. To enable logging, you must create a log handler:

myLogger := slog.New(slog.NewJSONHandler(os.Stdout, nil))

for JSON output and

myLogger := slog.New(slog.NewTextHandler(os.Stdout, nil))

for text output. The bag.SetLogger() function makes sure that the called libraries use the same logger.

Using the logger#

The logger can be used like this:

bag.Logger.Info("Read font file", "filename", myfontfile)

which outputs (in JSON)

    "msg":"Read font file",

You can use bag.Logger to set the default logger: