Code Monkey home page Code Monkey logo

log-emitter's Introduction

NAME

Log::Emitter - Simple logger

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');

DESCRIPTION

Log::Emitter is a simple logger based on Mojo::Log.

Log::Emitter is compatible with Log::Contextual 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" };

EVENTS

Log::Emitter composes all events from Role::EventEmitter in addition to emitting the following.

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;
});

ATTRIBUTES

Log::Emitter implements the following attributes.

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";
});

handle

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

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

history

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

The last few logged messages.

level

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

Active log level, defaults to debug. Available log levels are debug, info, warn, error and fatal, in that order. Note that the LOG_EMITTER_LEVEL environment variable can override this value.

max_history_size

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

Maximum number of logged messages to store in "history", defaults to 10.

path

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

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

METHODS

Log::Emitter composes all methods from Role::EventEmitter in addition to the following.

new

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

Construct a new Log::Emitter object and subscribe to "message" event with default logger.

append

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

Append message to "handle".

debug

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

Emit "message" event and log debug message.

error

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

Emit "message" event and log error message.

fatal

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

Emit "message" event and log fatal message.

info

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

Emit "message" event and log info message.

is_debug

my $bool = $log->is_debug;

Check for debug log level.

is_error

my $bool = $log->is_error;

Check for error log level.

is_fatal

my $bool = $log->is_fatal;

Always true.

is_info

my $bool = $log->is_info;

Check for info log level.

is_warn

my $bool = $log->is_warn;

Check for warn log level.

warn

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

Emit "message" event and log warn message.

BUGS

Report any issues on the public bugtracker.

AUTHOR

Dan Book <[email protected]>

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)

SEE ALSO

Mojo::Log, Log::Contextual

log-emitter's People

Contributors

grinnz avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.