GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Mojo::Log::Role::Clearable(3) User Contributed Perl Documentation Mojo::Log::Role::Clearable(3)

Mojo::Log::Role::Clearable - Role for Mojo::Log with clearable log handle

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

Mojo::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.

Mojo::Log::Role::Clearable augments the following attributes.

 $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.

Mojo::Log::Role::Clearable composes the following methods.

 $log->clear_handle;

Clears "handle" in Mojo::Log attribute, it will be reopened from the "path" in Mojo::Log attribute when next accessed.

Dan Book, "dbook@cpan.org"

Copyright 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.

Mojo::Log, Mojo::Log::Clearable

2021-06-16 perl v5.40.2

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.