NAME

Punk::Logger - a level-based logger

SYNOPSIS

get '/books' => sub {
    my ($c) = @_;
    $c->log->info('listing books');
    my @books = eval { ... } or $c->log->error('db down: %s', $@);
    $c->json(\@books);
};

# configure (optional - it works with none)
logging level => 'debug', format => 'json';

DESCRIPTION

$c->log is a request logger (it tags each line with the request method and path) and $app->log the application logger. Both offer debug, info, warn, error and fatal - a single argument is the message, several are sprintf($format, @args) - and a generic log($level, ... ). Each returns the logger, so calls chain.

Output goes to the server's psgix.logger when one is provided (the PSGI logging convention - the server owns routing and formatting), and otherwise to STDERR as [<ISO-8601 UTC>] [<level>] <method> <path> - <message>. It works with no configuration.

A call below the configured level does no formatting at all, and a failing sink never takes the request down.

CONFIGURATION

logging
    level  => 'info',      # debug < info < warn < error < fatal
    format => 'plain',     # or 'json' - one object per line
    to     => \*STDOUT;    # a filehandle or coderef; default STDERR

Also from punk.yml under a logging: block. STDERR is the deliberate default (let the platform route it); point to at a coderef or filehandle, or provide a psgix.logger, for anything else.

METHODS

debug / info / warn / error / fatal ($message | $format, @args)

Log at that level. Chainable.

log($level, $message | $format, @args)

The level-first form.

SEE ALSO

Punk, "log" in Punk::Context.

AUTHOR

LNATION <email@lnation.org>

LICENSE AND COPYRIGHT

This software is Copyright (c) 2026 by LNATION <email@lnation.org>.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)