Authen::Simple::Log - Simple log class


Authen-Simple documentation Contained in the Authen-Simple distribution.

Index


Code Index:

NAME

Top

Authen::Simple::Log - Simple log class

SYNOPSIS

Top

    $log = Authen::Simple::Log->new;
    $log->error($message);
    $log->warn($message);

DESCRIPTION

Top

Default log class for Authen::Simple

METHODS

Top

* new

Constructor, takes no parameters.

* debug (@)

Does nothing.

* error (@)

Logs a error message to STDERR.

* info (@)

Does nothing.

* warn (@)

Logs a warning message to STDERR if $^W is true.

SEE ALSO

Top

Authen::Simple

Authen::Simple::Adapter

AUTHOR

Top

Christian Hansen ch@ngmedia.com

COPYRIGHT

Top


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__