NAME

Log::Any::Adapter::Daemontools - Logging adapter suitable for use in a Daemontools-style logging chain

VERSION

version 0.002000

DESCRIPTION

In the daemontools way of thinking, a daemon writes all its logging output to STDOUT, which is a pipe to a logger process. When writing all log info to a pipe, you lose the log level information. An elegantly simple way to preserve this information is to prefix each line with "error:" or etc.

This is a small simple module that writes logging messages to STDOUT, prefixing each line with an identifier like "error: ", "warning: ", etc.

For the Debug and Trace log levels, it additionally wraps the message with an eval {}, and converts any non-scalar message parts into strings using Data::Dumper or similar. This allows debug messages to dump objects without worry that the stringification would cause a fatal exception.

All other log levels are considered "important" such that you want the exception if they fail, and arguments are converted to strings however they normally would if you tried printing them, on the assumption that if you print an object in the course of normal logging then you probably want the natural stringification for that type of object.

ATTRIBUTES

filter

use Log::Any::Adapter 'Daemontools', filter => 0;
use Log::Any::Adapter 'Daemontools', filter => 'info';
use Log::Any::Adapter 'Daemontools', filter => 'debug';
use Log::Any::Adapter 'Daemontools', filter => "debug-$ENV{DEBUG}";

Messages equal to or less than the level of filter are suppressed.

The default filter is 0, meaning 'info' and below are suppressed.

filter may be:

  • an integer (1 is notice, 0 is info, -1 is debug, etc)

  • a level name like 'info', 'debug', etc, or a level alias as documented in Log::Any.

  • undef, or the string 'none', which do not suppress anything

  • a special notation matching /debug-(\d+)/, where a number will be subtracted from the debug level

    This is useful for quickly setting a log level from $ENV{DEBUG} using the following code:

    use Log::Any::Adapter 'Daemontools', filter => "debug-".($ENV{DEBUG}||0);

    so that DEBUG=1 causes debug to be shown, but not trace, and DEBUG=2 causes both debug and trace to show.

dumper

use Log::Any::Adapter 'Daemontools', dumper => sub { my $val=shift; ... };

Use a custom dumper function for converting perl data to strings. The dumper is only used for the "*f()" formatting functions, and for log levels 'debug' and 'trace'. All normal logging will stringify the object in the normal way.

METHODS

This logger has a method for all of the standard logging methods as of Log::Any version 0.15

I decided to base my class on Moo rather than Log::Any::Adapter::Core, so it is possible this module will need updated in the future, though Log::Any's API should be pretty stable.

new

$class->new( filter => 'notice', dumper => sub { ... } )

use Log::Any::Adapter 'Daemontools', filter => 'notice', dumper => sub { ... };

Log::Any::Adapter->set('Daemontools', filter => 'notice', dumper => sub { ... });

Construct a new instance of the logger, in a variety of ways. Accepted paramters are currently 'filter' and 'dumper'.

write_msg

$self->write_msg( $level_name, $message_string )

This is an internal method which all the other logging methods call. You can override it if you want to create a derived logger that handles line wrapping differently, or write to a file handle other than STDOUT.

_default_dumper

$string = _default_dumper( $perl_data );

This is a function which dumps a value in a human readable format. Currently it uses Data::Dumper with a max depth of 4, but might change in the future.

This is the default value for the 'dumper' attribute.

SEE ALSO

Process Supervision Tools

Daemontools

The pioneer of the design:

http://cr.yp.to/daemontools.html

Runit

A popular re-implementation of the same idea:

http://smarden.org/runit

Also available as a busybox applet:

http://busybox.org

Perp

A variation that uses a single process to supervise many jobs:

http://b0llix.net/perp/

s6

Extreme minimalist supervisor with high level of attention to detail.

http://skarnet.org/software/s6/

Also see discussion and comparison of tools at http://skarnet.org/software/s6/why.html

Daemonproxy

Scriptable supervision tool that lets you easily build your own supervisor.

http://www.nrdvana.net/daemonproxy/

Useful Loggers

Tinylog

Basic log-to-file with rotation built-in.

http://b0llix.net/perp/site.cgi?page=tinylog.8

Sissylog

Log to syslog, using prefixes to determine log level

http://b0llix.net/perp/site.cgi?page=sissylog.8

s6-log

Filter log messages into files by pattern, with many useful features.

http://skarnet.org/software/s6/s6-log.html

AUTHOR

Michael Conrad <mike@nrdvana.net>

COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by Michael Conrad.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.