line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Context::Log; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
38155
|
use Moose; |
|
2
|
|
|
|
|
337670
|
|
|
2
|
|
|
|
|
14
|
|
4
|
2
|
|
|
2
|
|
11047
|
use version; |
|
2
|
|
|
|
|
1478
|
|
|
2
|
|
|
|
|
13
|
|
5
|
2
|
|
|
2
|
|
124
|
use Carp qw/longmess/; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
137
|
|
6
|
2
|
|
|
2
|
|
8
|
use Data::Dumper qw/Dumper/; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
852
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = version->new('0.1.10'); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my $last; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has level => ( is => 'rw', isa => 'Int', default => 3 ); |
13
|
|
|
|
|
|
|
has fh => ( is => 'ro', default => sub {\*STDERR} ); |
14
|
|
|
|
|
|
|
sub BUILD { |
15
|
6
|
|
|
6
|
1
|
6273
|
my ($self) = @_; |
16
|
6
|
|
|
|
|
8
|
$last = $self; |
17
|
6
|
|
|
|
|
20
|
return; |
18
|
|
|
|
|
|
|
}; |
19
|
|
|
|
|
|
|
sub debug { |
20
|
3
|
|
|
3
|
1
|
814
|
my ($self, @message) = @_; |
21
|
3
|
100
|
|
|
|
9
|
$self = $last if !ref $self; |
22
|
3
|
100
|
|
|
|
100
|
$self->_log( 'DEBUG', @message ) if $self->level <= 1; |
23
|
3
|
|
|
|
|
4
|
return; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
sub info { |
26
|
3
|
|
|
3
|
1
|
592
|
my ($self, @message) = @_; |
27
|
3
|
100
|
|
|
|
10
|
$self = $last if !ref $self; |
28
|
3
|
100
|
|
|
|
95
|
$self->_log( 'INFO ' , @message ) if $self->level <= 2; |
29
|
3
|
|
|
|
|
5
|
return; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
sub warn { ## no critic |
32
|
3
|
|
|
3
|
1
|
512
|
my ($self, @message) = @_; |
33
|
3
|
100
|
|
|
|
8
|
$self = $last if !ref $self; |
34
|
3
|
100
|
|
|
|
80
|
$self->_log( 'WARN ' , @message, longmess ) if $self->level <= 3; |
35
|
3
|
|
|
|
|
6
|
return; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
sub error { |
38
|
3
|
|
|
3
|
1
|
521
|
my ($self, @message) = @_; |
39
|
3
|
100
|
|
|
|
7
|
$self = $last if !ref $self; |
40
|
3
|
100
|
|
|
|
81
|
$self->_log( 'ERROR', @message, longmess ) if $self->level <= 4; |
41
|
3
|
|
|
|
|
5
|
return; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
sub fatal { |
44
|
3
|
|
|
3
|
1
|
561
|
my ($self, @message) = @_; |
45
|
3
|
100
|
|
|
|
8
|
$self = $last if !ref $self; |
46
|
3
|
100
|
|
|
|
84
|
$self->_log( 'FATAL', @message, longmess ) if $self->level <= 5; |
47
|
3
|
|
|
|
|
25
|
return; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub _log { |
51
|
15
|
|
|
15
|
|
1928
|
my ($self, $level, @message) = @_; |
52
|
15
|
100
|
|
|
|
33
|
$self = $last if !ref $self; |
53
|
15
|
100
|
100
|
|
|
63
|
$message[0] = Dumper $message[0] if @message == 1 && ( ref $message[0] || !defined $message[0] ); |
|
|
|
66
|
|
|
|
|
54
|
15
|
|
|
|
|
155
|
chomp $message[-1]; |
55
|
15
|
|
|
|
|
18
|
print {$self->fh} localtime() . " [$level] ", join ' ', @message, "\n"; |
|
15
|
|
|
|
|
411
|
|
56
|
15
|
|
|
|
|
269
|
return; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
__END__ |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 NAME |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Data::Context::Log - Simple Log object helper |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 VERSION |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
This documentation refers to Data::Context::Log version 0.1.10 |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 SYNOPSIS |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
use Data::Context::Log; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# Brief but working code example(s) here showing the most common usage(s) |
76
|
|
|
|
|
|
|
# This section will be as far as many users bother reading, so make it as |
77
|
|
|
|
|
|
|
# educational and exemplary as possible. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 DESCRIPTION |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Very simple log object it only really exists as a place holder for more |
83
|
|
|
|
|
|
|
sophisticated log objects (eg L<Log::Log4perl>). |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 new |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Has one optional parameter C<level> (default is 3) which sets the cut off |
90
|
|
|
|
|
|
|
level for showing log messages. Setting level to 1 shows all messages, setting |
91
|
|
|
|
|
|
|
level to 5 will show only fatal error messages. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head2 BUILD |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Construction activities |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=over 4 |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=item debug |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Requires level 1 to be displayed |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=item info |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Requires level 2 to be displayed |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=item warn |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Requires level 3 to be displayed |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=item error |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Requires level 4 to be displayed |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=item fatal |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Requires level 5 to be displayed |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=back |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 DIAGNOSTICS |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 CONFIGURATION AND ENVIRONMENT |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 INCOMPATIBILITIES |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
There are no known bugs in this module. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Please report problems to Ivan Wills (ivan.wills@gmail.com). |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Patches are welcome. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 AUTHOR |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Ivan Wills - (ivan.wills@gmail.com) |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Copyright (c) 2013 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077). |
144
|
|
|
|
|
|
|
All rights reserved. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify it under |
147
|
|
|
|
|
|
|
the same terms as Perl itself. See L<perlartistic>. This program is |
148
|
|
|
|
|
|
|
distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
149
|
|
|
|
|
|
|
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
150
|
|
|
|
|
|
|
PARTICULAR PURPOSE. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=cut |