FuguLib::Log(3p) Perl Library Manual FuguLib::Log(3p)

FuguLib::Loglogging to syslog, standard error, or nowhere

use FuguLib::Log;

my $log = FuguLib::Log->new(
    mode     => 'syslog',
    ident    => 'mydaemon',
    level    => 'info',
    facility => 'daemon',
);

$log->info('listening on port %d', $port);
$log->err('cannot open %s: %s', $path, $!);

FuguLib::Log gives a program one logging interface whether it is running as a daemon or in the foreground. The destination is chosen once, when the logger is created, and every call site is written the same way regardless.

Messages below the configured level are discarded. The levels, from lowest to highest, are debug, info, notice, warning, error and crit.

(%args) creates a logger. The arguments are as follows:

mode
Where messages go. One of:

Through syslog(3). openlog(3) is called immediately with the ndelay and pid options.
To standard error, one line per message, prefixed with a local-time stamp and the upper-cased level.
Nowhere. Messages are discarded before the level is even considered.

The default is stderr.

level
Lowest level to emit. The default is info.
ident
Program name passed to openlog(3). The default is ‘fugulib’. Ignored unless mode is syslog.
facility
Syslog facility, either a Sys::Syslog(3p) constant or one of the names daemon, user or local0 through local7. The default is LOG_DAEMON.

$log->info($fmt, @args);

Log one message at the level named by the method. When @args is non-empty the message is $fmt formatted through sprintf(3); otherwise $fmt is used literally.

() is a synonym for () and () for (), so that either the syslog or the English spelling reads naturally at the call site.

set_level($level) changes the lowest level to emit on an existing logger. Anything not recognised as a level name is treated as info.

new() returns a logger object. The logging methods and set_level() have no useful return value.

Log to standard error in the foreground and to syslog otherwise, without changing any call site:

my $log = FuguLib::Log->new(
    mode  => $foreground ? 'stderr' : 'syslog',
    ident => 'mydaemon',
    level => $verbose ? 'debug' : 'info',
);

new() dies if mode is not one of the three names above. An unrecognised level or facility is not an error: the level falls back to info and the facility to LOG_DAEMON.

syslog(3), FuguLib::Daemon(3p), Sys::Syslog(3p), syslog.conf(5)

Dick Olsson <hi@senzilla.io>

The format string is passed to sprintf(3) only when arguments follow it. A message that happens to contain a percent sign is therefore safe on its own but not once an argument is added, so log variable text as ‘%s’ rather than interpolating it into the format.

A single process should create one syslog-mode logger. openlog(3) and closelog(3) act on process-wide state, so a second logger going out of scope closes the connection the first one is still using.

July 27, 2026 OpenBSD