| Authen-Simple documentation | Contained in the Authen-Simple distribution. |
Authen::Simple::Log - Simple log class
$log = Authen::Simple::Log->new;
$log->error($message);
$log->warn($message);
Default log class for Authen::Simple
Constructor, takes no parameters.
Does nothing.
Logs a error message to STDERR.
Does nothing.
Logs a warning message to STDERR if $^W is true.
Christian Hansen ch@ngmedia.com
This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself.
| Authen-Simple documentation | Contained in the Authen-Simple distribution. |
package Authen::Simple::Log; use strict; use warnings; use IO::Handle; our $SINGLETON = bless( {}, __PACKAGE__ ); sub new { $SINGLETON } sub debug { } sub error { shift->_log( 'error', @_ ) } sub info { } sub warn { shift->_log( 'warn', @_ ) if $^W } sub _caller { my $self = shift; my $frame = 0; $frame++ until ( caller($frame) ne __PACKAGE__ ); return scalar caller($frame); } sub _format { my ( $self, $level, @message ) = @_; return sprintf( "[%s] [%s] [%s] %s\n", scalar localtime(), $level, $self->_caller, "@message" ); } sub _output { my $self = shift; STDERR->print(@_); STDERR->flush; } sub _log { my $self = shift; my $message = $self->_format(@_); $self->_output($message); } 1; __END__