Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/grinnz/log-emitter

Log::Emitter - Simple logger
https://github.com/grinnz/log-emitter

Last synced: 5 days ago
JSON representation

Log::Emitter - Simple logger

Awesome Lists containing this project

README

        

=pod

=encoding utf8

=head1 NAME

Log::Emitter - Simple logger

=head1 SYNOPSIS

use Log::Emitter;

# Log to STDERR
my $log = Log::Emitter->new;

# Customize log file location and minimum log level
my $log = Log::Emitter->new(path => '/var/log/emitter.log', level => 'warn');

# Log messages
$log->debug('Not sure what is happening here');
$log->info('FYI: it happened again');
$log->warn('This might be a problem');
$log->error('Garden variety error');
$log->fatal('Boom');

=head1 DESCRIPTION

L is a simple logger based on L.

L is compatible with L for global logging.

use Log::Emitter;
use Log::Contextual ':log', 'set_logger', -levels => [qw(debug info warn error fatal)];
set_logger(Log::Emitter->new);

log_info { "Here's some info" };
log_error { "Uh-oh, error occured" };

=head1 EVENTS

L composes all events from L in addition to
emitting the following.

=head2 message

$log->on(message => sub {
my ($log, $level, @lines) = @_;
...
});

Emitted when a new message gets logged.

$log->unsubscribe('message');
$log->on(message => sub {
my ($log, $level, @lines) = @_;
say "$level: ", @lines;
});

=head1 ATTRIBUTES

L implements the following attributes.

=head2 format

my $cb = $log->format;
$log = $log->format(sub {...});

A callback for formatting log messages.

$log->format(sub {
my ($time, $level, @lines) = @_;
return "[Thu May 15 17:47:04 2014] [info] I ♥ Logging\n";
});

=head2 handle

my $handle = $log->handle;
$log = $log->handle(IO::Handle->new);

Log filehandle used by default L"message"> event, defaults to opening
L"path"> or C. Reset when L"path"> is set.

=head2 history

my $history = $log->history;
$log = $log->history([[time, 'debug', 'That went wrong']]);

The last few logged messages.

=head2 level

my $level = $log->level;
$log = $log->level('debug');

Active log level, defaults to C. Available log levels are C,
C, C, C and C, in that order. Note that the
C environment variable can override this value.

=head2 max_history_size

my $size = $log->max_history_size;
$log = $log->max_history_size(5);

Maximum number of logged messages to store in L"history">, defaults to C<10>.

=head2 path

my $path = $log->path
$log = $log->path('/var/log/emitter.log');

Log file path used by L"handle">. Setting this attribute will reset
L"handle">.

=head1 METHODS

L composes all methods from L in addition to
the following.

=head2 new

my $log = Log::Emitter->new;

Construct a new L object and subscribe to L"message"> event
with default logger.

=head2 append

$log->append("[Thu May 15 17:47:04 2014] [info] I ♥ Logging\n");

Append message to L"handle">.

=head2 debug

$log = $log->debug('You screwed up, but that is ok');
$log = $log->debug('All', 'cool');

Emit L"message"> event and log debug message.

=head2 error

$log = $log->error('You really screwed up this time');
$log = $log->error('Wow', 'seriously');

Emit L"message"> event and log error message.

=head2 fatal

$log = $log->fatal('Its over...');
$log = $log->fatal('Bye', 'bye');

Emit L"message"> event and log fatal message.

=head2 info

$log = $log->info('You are bad, but you prolly know already');
$log = $log->info('Ok', 'then');

Emit L"message"> event and log info message.

=head2 is_debug

my $bool = $log->is_debug;

Check for debug log level.

=head2 is_error

my $bool = $log->is_error;

Check for error log level.

=head2 is_fatal

my $bool = $log->is_fatal;

Always true.

=head2 is_info

my $bool = $log->is_info;

Check for info log level.

=head2 is_warn

my $bool = $log->is_warn;

Check for warn log level.

=head2 warn

$log = $log->warn('Dont do that Dave...');
$log = $log->warn('No', 'really');

Emit L"message"> event and log warn message.

=head1 BUGS

Report any issues on the public bugtracker.

=head1 AUTHOR

Dan Book

=head1 COPYRIGHT AND LICENSE

This software is Copyright (c) 2015 by Dan Book.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)

=head1 SEE ALSO

L, L

=for Pod::Coverage BUILD

=cut