| 1 | package WebSource::Logger; | ||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | |||||||||||||||
| 4 | =head1 NAME | ||||||||||||||
| 5 | |||||||||||||||
| 6 | WebSource::Logger : WebSource logging module | ||||||||||||||
| 7 | |||||||||||||||
| 8 | =head1 DESCRIPTION | ||||||||||||||
| 9 | |||||||||||||||
| 10 | Configurable logging module | ||||||||||||||
| 11 | |||||||||||||||
| 12 | =head1 SYNOPSIS | ||||||||||||||
| 13 | |||||||||||||||
| 14 | use WebSource::Logger(level => $loglevel); | ||||||||||||||
| 15 | my $logger->log($level,$message); | ||||||||||||||
| 16 | |||||||||||||||
| 17 | =head1 METHODS | ||||||||||||||
| 18 | |||||||||||||||
| 19 | =over 1 | ||||||||||||||
| 20 | |||||||||||||||
| 21 | =item $logger = WebSource::Logger->new( level => $loglevel ) | ||||||||||||||
| 22 | |||||||||||||||
| 23 | Create a new logging object | ||||||||||||||
| 24 | |||||||||||||||
| 25 | =cut | ||||||||||||||
| 26 | |||||||||||||||
| 27 | 0 | ▶ | sub new { | ||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||
| 28 | 0 | my $class = shift; | |||||||||||||
| 29 | 0 | my %params = @_; | |||||||||||||
| 30 | 0 | ▶ | $params{level} or $params{level} = 3; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 31 | 0 | ▶ | $params{date} or $params{date} = 0; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 32 | 0 | return bless \%params, $class; | |||||||||||||
| 33 | } | ||||||||||||||
| 34 | |||||||||||||||
| 35 | =item $logger->log($level,$message); | ||||||||||||||
| 36 | |||||||||||||||
| 37 | Log $message if the current log level is superior or equal to $level | ||||||||||||||
| 38 | |||||||||||||||
| 39 | =cut | ||||||||||||||
| 40 | |||||||||||||||
| 41 | 0 | ▶ | sub log { | ||||||||||||
|
Subroutine
log: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||
| 42 | 0 | my $self = shift; | |||||||||||||
| 43 | 0 | my $level = shift; | |||||||||||||
| 44 | $level <= $self->{level} and | ||||||||||||||
| 45 | 0 | ▶ | print STDERR ($self->{date} ? scalar(localtime) . " : " : ""), @_,"\n"; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 46 | } | ||||||||||||||
| 47 | |||||||||||||||
| 48 | |||||||||||||||
| 49 | =item $logger->will_log($level); | ||||||||||||||
| 50 | |||||||||||||||
| 51 | Check if a message logged at level C<$level> will be logged or not. | ||||||||||||||
| 52 | This is typically to prevent processing in preperation for loggin data. | ||||||||||||||
| 53 | |||||||||||||||
| 54 | =cut | ||||||||||||||
| 55 | |||||||||||||||
| 56 | 0 | ▶ | sub will_log { | ||||||||||||
|
Subroutine
will_log: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 57 | 0 | my ($self,$level) = @_; | |||||||||||||
| 58 | 0 | return ($level <= $self->{level}); | |||||||||||||
| 59 | } | ||||||||||||||
| 60 | |||||||||||||||
| 61 | =head1 SEE ALSO | ||||||||||||||
| 62 | |||||||||||||||
| 63 | WebSource | ||||||||||||||
| 64 | |||||||||||||||
| 65 | =cut | ||||||||||||||
| 66 | |||||||||||||||
| 67 | 1 | 1; | |||||||||||||