Table of Contents


selog - selective logging


require "selog"

-- intialization, {name1, name2, ...})

-- creating selectors
local sel =, level)
local sel = selog(name, level)
local sel = selog(name, “fatal(status)”)
local sel = selog(name, “fatal”, status)

-- inspecting selectors
local name =
local level = sel.level
local status = sel.exitval

if sel.on then ... end

-- logging


Selog is a library of routines that unifies error reporting, activity logging, and debug tracing. It allows programmers to give their users flexible control over which messages are written and where they are written to.

This manual Lua interface to selog by reference to the C manual, selog(3), and the end-user manual, selog(7).


To configure and reconfigure selog, call passing the configuration string as the first argument. The configuration syntax and other details are described in selog(7). If you want selog to check the category names in the configuration, you should pass an array-like table as the second argument that lists all the valid names. More details can be found in the “INITIALIZATION” section of selog(3).

Creating selectors

Logging is performed using selectors, which are created by calling or just selog() itself. This takes two string arguments: the selector’s category name and its level. More details can be found in the “SELECTORS” section of selog(3). The string equivalents for the levels are listed in selog(7). To specify the exit status of a “fatal” selector, you can either put it in round brackets at the end of the level string, or you can pass it as a third argument.

Inspecting selectors

You can extract information about a selector by treating it like a table. The available keys are:
The exit status for “fatal” selectors, and nil for others.
The canonical name of the selector’s level.
The category name given when the selector was created.
A boolean value that is true if the selector is enabled. This can be used to disable message preparation code when a selector is disabled.


To log a message, just call the selector. The arguments are concatenated with spaces between. If the selector’s level is “trace” then the message includes debug information about the caller.

See Also

selog(3), selog(7)


Written by Tony Finch <> <>
at the University of Cambridge Computing Service.
Source available from <>

Table of Contents