The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

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

VERSION

version 0.001002

DESCRIPTION

In the daemontools way of thinking, a daemon writes all its logging output to STDERR, 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 STDERR, 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 howver 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.

filter may be an integer (0 is info, 1 is notice, -1 is debug, etc) or a level name like 'info', 'debug', etc, or a level alias, the string 'none' or undef which do not suppress anything, or a special notation of /debug-(\d+)/, where a number will be subtracted from the debug level (this is useful for quickly setting a log level from $ENV{DEBUG})

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

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 Log::Any methods (as of the time this was written... I did not inherit from the Log::Any::Adapter::Core base class)

new

  $class->new( filter => 'notice', dumper => sub { ... } )
  
  use Log::Any::Adapter 'Daemonproxy', filter => 'notice', dumper => sub { ... };
  
  Log::Any::Adapter->set('Daemonproxy', 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 STDERR.

_default_dumper

  _default_dumper( $value )

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.

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.