|
NAMEMojo::Log::Role::Clearable - Role for Mojo::Log with clearable log handle SYNOPSIS use Mojo::Log;
my $log = Mojo::Log->with_roles('+Clearable')->new(path => $path1);
$log->info($message); # Logged to $path1
$log->path($path2);
$log->debug($message); # Logged to $path2
$log->path(undef);
$log->warn($message); # Logged to STDERR
# Reopen filehandle after logrotate (if logrotate sends SIGUSR1)
$SIG{USR1} = sub { $log->clear_handle };
# Apply to an existing Mojo::Log object
$app->log->with_roles('+Clearable');
DESCRIPTIONMojo::Log is a simple logger class. It holds a filehandle once it writes to a log, and changing "path" in Mojo::Log does not open a new filehandle for logging. Mojo::Log::Role::Clearable is a role that provides a "clear_handle" method and automatically calls it when "path" in Mojo::Log is modified, so the logging handle is reopened at the new path. The "clear_handle" method can also be used to reopen the logging handle after logrotate. ATTRIBUTESMojo::Log::Role::Clearable augments the following attributes. path $log = $log->path('/var/log/mojo.log'); # "handle" is now cleared
Log file path as in "path" in Mojo::Log. Augmented to call "clear_handle" when modified. METHODSMojo::Log::Role::Clearable composes the following methods. clear_handle$log->clear_handle; Clears "handle" in Mojo::Log attribute, it will be reopened from the "path" in Mojo::Log attribute when next accessed. AUTHORDan Book, "dbook@cpan.org" COPYRIGHT AND LICENSECopyright 2015, Dan Book. This library is free software; you may redistribute it and/or modify it undef the terms of the Artistic License version 2.0. SEE ALSOMojo::Log, Mojo::Log::Clearable
|