line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Prancer::Logger::Console; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
9769
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
119
|
|
4
|
4
|
|
|
4
|
|
10
|
use warnings FATAL => 'all'; |
|
4
|
|
|
|
|
3
|
|
|
4
|
|
|
|
|
123
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
17
|
use Carp; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
184
|
|
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
1098
|
use Time::HiRes (); |
|
4
|
|
|
|
|
3463
|
|
|
4
|
|
|
|
|
154
|
|
9
|
|
|
|
|
|
|
|
10
|
4
|
|
|
|
|
1662
|
use constant LEVELS => { |
11
|
|
|
|
|
|
|
DEBUG => 4, |
12
|
|
|
|
|
|
|
INFO => 3, |
13
|
|
|
|
|
|
|
WARN => 2, |
14
|
|
|
|
|
|
|
ERROR => 1, |
15
|
|
|
|
|
|
|
FATAL => 0, |
16
|
4
|
|
|
4
|
|
15
|
}; |
|
4
|
|
|
|
|
3
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new { |
19
|
0
|
|
|
0
|
0
|
|
my ($class, $config) = @_; |
20
|
0
|
|
|
|
|
|
my $self = bless({}, $class); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
0
|
|
0
|
|
|
|
my $level = uc($config->{'level'} || "info"); |
24
|
0
|
0
|
|
|
|
|
die "invalid default log level: ${level}\n" unless ($level =~ /^(debug|info|warn|error|fatal)$/xi); |
25
|
0
|
|
|
|
|
|
$self->{'_level'} = LEVELS->{$level}; |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
return $self; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub _log { |
31
|
0
|
|
|
0
|
|
|
my ($self, $level, $message) = @_; |
32
|
|
|
|
|
|
|
|
33
|
0
|
0
|
|
|
|
|
croak "invalid message log level ${level}\n" unless ($level =~ /^(debug|info|warn|error|fatal)$/xi); |
34
|
0
|
0
|
|
|
|
|
return if (LEVELS->{uc($level)} > $self->{'_level'}); |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my ($seconds, $microseconds) = Time::HiRes::gettimeofday(); |
37
|
0
|
|
|
|
|
|
my ($second, $minute, $hour, $day, $month, $year) = localtime($seconds); |
38
|
0
|
|
|
|
|
|
$message =~ s/^\s+|\s+$//xgs; |
39
|
0
|
|
|
|
|
|
print STDOUT sprintf("%04d-%02d-%02d %02d:%02d:%02d,%03d %5s - %s\n", ($year + 1900), ($month + 1), $day, $hour, $minute, $second, ($microseconds / 1000), uc($level), $message); |
40
|
0
|
|
|
|
|
|
return; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub debug { |
44
|
0
|
|
|
0
|
0
|
|
my ($self, $message) = @_; |
45
|
0
|
|
|
|
|
|
$self->_log("debug", $message); |
46
|
0
|
|
|
|
|
|
return; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub info { |
50
|
0
|
|
|
0
|
0
|
|
my ($self, $message) = @_; |
51
|
0
|
|
|
|
|
|
$self->_log("info", $message); |
52
|
0
|
|
|
|
|
|
return; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub warn { |
57
|
0
|
|
|
0
|
0
|
|
my ($self, $message) = @_; |
58
|
0
|
|
|
|
|
|
$self->_log("warn", $message); |
59
|
0
|
|
|
|
|
|
return; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub error { |
63
|
0
|
|
|
0
|
0
|
|
my ($self, $message) = @_; |
64
|
0
|
|
|
|
|
|
$self->_log("error", $message); |
65
|
0
|
|
|
|
|
|
return; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub fatal { |
69
|
0
|
|
|
0
|
0
|
|
my ($self, $message) = @_; |
70
|
0
|
|
|
|
|
|
$self->_log("fatal", $message); |
71
|
0
|
|
|
|
|
|
return; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 NAME |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Prancer::Logger::Console |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 SYNOPSIS |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
This module configures a logger that sends log messages directly to STDOUT. |
83
|
|
|
|
|
|
|
This is the default logger if no other logger is configured. If you wish to |
84
|
|
|
|
|
|
|
configure this logger explicitly, add this to your configuration file: |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
logger: |
87
|
|
|
|
|
|
|
driver: Prancer::Logger::Console |
88
|
|
|
|
|
|
|
options: |
89
|
|
|
|
|
|
|
level: debug |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 OPTIONS |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=over 4 |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=item level |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Set the default logging level. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=back |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=cut |
102
|
|
|
|
|
|
|
|