NAME

Mojo::Log - Simple Logger For Mojo

SYNOPSIS

use Mojo::Log;

# Create a logging object that will log to STDERR by default
my $log = Mojo::Log->new;

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

$log->debug("Why isn't this working?");
$log->info("FYI: it happened again");
$log->warn("This might be a problem");
$log->error("Garden variety error");
$log->fatal("Boom!");

DESCRIPTION

Mojo::Log is a simple logger. Include log statements at various levels throughout your code. Then when you create the new logging object, set the minimum log level you want to keep track off. Set it low, to 'debug' for development, then higher in production.

ATTRIBUTES

handle

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

Returns a IO handle used for logging if called without arguments. Returns the invocant if called with arguments. Any object with a syswrite method will do.

level

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

Returns the minimum logging level if called without arguments. Returns the invocant if called with arguments. Valid value are: debug, info, warn, error and fatal.

path

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

Returns the path of the log file to write to if called without arguments. Returns the invocant if called with arguments. This is used as the default location for handle, STDERR will be used if no path is provided.

METHODS

Mojo::Log inherits all methods from Mojo::Base and implements the following new ones.

debug

$log = $log->debug('You screwed up, but thats ok');

error

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

fatal

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

info

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

is_level

my $is = $log->is_level('debug');

Returns true if the current logging level is at or above this level.

is_debug

my $is = $log->is_debug;

Returns true if the current logging level is at or above this level.

is_error

my $is = $log->is_error;

Returns true if the current logging level is at or above this level.

is_fatal

my $is = $log->is_fatal;

Returns true if the current logging level is at or above this level.

is_info

my $is = $log->is_info;

Returns true if the current logging level is at or above this level.

is_warn

my $is = $log->is_warn;

Returns true if the current logging level is at or above this level.

log

$log = $log->log(debug => 'This should work');

A long-hand alternative to the logging shortcuts above.

warn

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

SEE ALSO

Log::Dispatch is an established logger with a similar interface, with many more options for logging backends.