Acrux
view release on metacpan or search on metacpan
lib/Acme/Crux/Plugin/Log.pm view on Meta::CPAN
package Acme::Crux::Plugin::Log;
use warnings;
use strict;
use utf8;
=encoding utf-8
=head1 NAME
Acme::Crux::Plugin::Log - The Acme::Crux plugin for logging in your application
=head1 SYNOPSIS
# In startup
$app->plugin('Log');
$app->plugin('Log', undef, { ... options ... });
# In application
$app->log->trace('Whatever');
$app->log->debug('You screwed up, but that is ok');
$app->log->info('You are bad, but you prolly know already');
$app->log->notice('Normal, but significant, condition...');
$app->log->warn('Dont do that Dave...');
$app->log->error('You really screwed up this time');
$app->log->fatal('Its over...');
$app->log->crit('Its over...');
$app->log->alert('Action must be taken immediately');
$app->log->emerg('System is unusable');
=head1 DESCRIPTION
The Acme::Crux plugin for logging in your application
=head1 OPTIONS
This plugin supports the following options
=head2 autoclean
$app->plugin(Log => undef, {autoclean => 1});
This option enables cleaning (closing handler or syslog) on DESTROY
Default: C<logautoclean> command line option or C<logautoclean> application argument
or C<LogAutoclean> configuration value or C<0> otherwise
=head2 color
$app->plugin(Log => undef, {color => 1});
This option enables colorize log messages with the available levels using L<Term::ANSIColor>
Default: C<logcolorize> command line option or C<logcolorize> application argument
or C<LogColorize> configuration value or C<0> otherwise
=head2 facility
$app->plugin(Log => undef, {facility => 'user'});
This option sets facility for logging
Available standard facilities: C<auth>, C<authpriv>, C<cron>, C<daemon>, C<ftp>,
C<kern>, C<local0>, C<local1>, C<local2>, C<local3>, C<local4>, C<local5>, C<local6>,
C<local7>, C<lpr>, C<mail>, C<news>, C<syslog>, C<user> and C<uucp>
Default: C<logfacility> command line option or C<logfacility> application argument
or C<LogFacility> configuration value or C<user> otherwise
=head2 file
$app->plugin(Log => undef, {file => '/var/log/myapp.log'});
Log file path used by "handle"
Default: C<logfile> command line option or C<LogFile> configuration value
or C<logfile> application argument or C</var/log/$moniker/$moniker.log> otherwise
=head2 format
$app->plugin(Log => undef, {format => sub {...}});
A callback function for formatting log messages. See L<Acrux::Log/format>
Default: C<logformat> application argument or C<undef> otherwise
=head2 handle
$app->plugin(Log => undef, {
handle => IO::Handle->new_from_fd(fileno(STDOUT), "w")
});
Log filehandle, defaults to opening "file" or uses syslog if file not specified
Default: C<loghandle> application argument or C<undef> otherwise
=head2 ident
$app->plugin(Log => undef, {ident => 'myapp'});
The B<ident> is prepended to every B<syslog> message
Default: C<logident> command line option or C<logident> application argument
or C<LogIdent> configuration value or script name C<basename($0)> otherwise
=head2 level
$app->plugin(Log => undef, {level => 'debug'});
This option sets log level
Predefined log levels: C<fatal>, C<error>, C<warn>, C<info>, C<debug>, and C<trace> (in descending priority).
The syslog supports followed additional log levels: C<emerg>, C<alert>, C<crit'> and C<notice> (in descending priority).
But we recommend not using them to maintain compatibility.
See also L<Acrux::Log/level>
Default: C<loglevel> command line option or C<loglevel> application argument
or C<LogLevel> configuration value or C<debug> otherwise
=head2 logger
$app->plugin(Log => undef, {logger => Mojo::Log->new()});
This option sets predefined logger, eg. Mojo::Log
Default: C<logger> application argument or C<undef> otherwise
=head2 logopt
$app->plugin(Log => undef, {logopt => 'ndelay,pid'});
This option contains zero or more of the options detailed in L<Sys::Syslog/openlog>
Default: C<logopt> command line option or C<logopt> application argument
or C<LogOpt> configuration value or C<'ndelay,pid'> otherwise
=head2 prefix
$app->plugin(Log => undef, {prefix => '>>>'});
The B<prefix> is prepended to every C<handled> log message
Default: C<logprefix> command line option or C<logprefix> application argument
or C<LogPrefix> configuration value or C<null> otherwise
=head2 provider
$app->plugin(Log => undef, {provider => 'syslog'});
This option select the provider of logging. Avalabled providers:
C<logger>, C<handler>, C<file> and C<syslog>.
Default: C<logprovider> command line option or C<logprovider> application argument
or C<LogProvider> configuration value or C<file> otherwise
=head2 short
$app->plugin(Log => undef, {short => 1});
Generate short log messages without a timestamp but with log level prefix
Default: C<logshort> command line option or C<logshort> application argument
or C<LogShort> configuration value or C<0> otherwise
=head1 METHODS
This class inherits all methods from L<Acme::Crux::Plugin> and implements the following new ones
=head2 register
$plugin->register($app, {file => '/var/log/app.log'});
Register plugin in Acme::Crux application
=head1 HELPERS
All helpers of this plugin are allows get access to logger object.
See L<Acrux::Log> for details
( run in 2.066 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )