line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Siffra::Logger; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
78214
|
use 5.014; |
|
1
|
|
|
|
|
3
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
15
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
17
|
|
6
|
1
|
|
|
1
|
|
3
|
use Carp; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
44
|
|
7
|
1
|
|
|
1
|
|
480
|
use utf8; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
5
|
|
8
|
1
|
|
|
1
|
|
510
|
use Data::Dumper; |
|
1
|
|
|
|
|
5451
|
|
|
1
|
|
|
|
|
48
|
|
9
|
1
|
|
|
1
|
|
372
|
use DDP; |
|
1
|
|
|
|
|
33337
|
|
|
1
|
|
|
|
|
9
|
|
10
|
1
|
|
|
1
|
|
47
|
use Scalar::Util qw(blessed); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
60
|
|
11
|
|
|
|
|
|
|
$Carp::Verbose = 1; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
$| = 1; #autoflush |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use constant { |
16
|
|
|
|
|
|
|
FALSE => 0, |
17
|
|
|
|
|
|
|
TRUE => 1, |
18
|
1
|
|
50
|
|
|
71
|
DEBUG => $ENV{ DEBUG } // 0, |
19
|
1
|
|
|
1
|
|
4
|
}; |
|
1
|
|
|
|
|
2
|
|
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
1
|
|
381
|
use Log::Any::Adapter; |
|
1
|
|
|
|
|
9007
|
|
|
1
|
|
|
|
|
4
|
|
22
|
1
|
|
|
1
|
|
403
|
use Log::Dispatch; |
|
1
|
|
|
|
|
188470
|
|
|
1
|
|
|
|
|
32
|
|
23
|
1
|
|
|
1
|
|
7
|
use File::Basename; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
84
|
|
24
|
1
|
|
|
1
|
|
6
|
use POSIX qw/strftime/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
BEGIN |
27
|
|
|
|
|
|
|
{ |
28
|
1
|
|
|
1
|
|
1327
|
use Exporter (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
29
|
1
|
|
|
1
|
|
4
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
105
|
|
30
|
1
|
|
|
1
|
|
3
|
$VERSION = '0.08'; |
31
|
1
|
|
|
|
|
13
|
@ISA = qw(Exporter); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
#Give a hoot don't pollute, do not export more than needed by default |
34
|
1
|
|
|
|
|
3
|
@EXPORT = qw(); |
35
|
1
|
|
|
|
|
2
|
@EXPORT_OK = qw(); |
36
|
1
|
|
|
|
|
2
|
%EXPORT_TAGS = (); |
37
|
|
|
|
|
|
|
|
38
|
1
|
|
|
1
|
|
23
|
binmode( STDOUT, ":encoding(UTF-8)" ); |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
39
|
1
|
|
|
|
|
9135
|
binmode( STDERR, ":encoding(UTF-8)" ); |
40
|
|
|
|
|
|
|
} ## end BEGIN |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 Log-Levels |
43
|
|
|
|
|
|
|
trace |
44
|
|
|
|
|
|
|
debug |
45
|
|
|
|
|
|
|
info (inform) |
46
|
|
|
|
|
|
|
notice |
47
|
|
|
|
|
|
|
warning (warn) |
48
|
|
|
|
|
|
|
error (err) |
49
|
|
|
|
|
|
|
critical (crit, fatal) |
50
|
|
|
|
|
|
|
alert |
51
|
|
|
|
|
|
|
emergency |
52
|
|
|
|
|
|
|
=cut |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
{ |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
$ENV{ LC_ALL } = $ENV{ LANG } = 'pt_BR.UTF-8'; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my ( $filename, $baseDirectory, $suffix ) = fileparse( $0, qr/\.[^.]*/ ); |
59
|
|
|
|
|
|
|
my $logDirectory = $baseDirectory . 'logs/'; |
60
|
|
|
|
|
|
|
my $logFilename = $filename . '.log'; |
61
|
|
|
|
|
|
|
croak( "Unable to create $logDirectory" ) unless ( -e $logDirectory or mkdir $logDirectory ); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my $dispatcher = Log::Dispatch->new( |
64
|
|
|
|
|
|
|
outputs => [ |
65
|
|
|
|
|
|
|
[ |
66
|
|
|
|
|
|
|
'Screen', |
67
|
|
|
|
|
|
|
name => 'screen', |
68
|
|
|
|
|
|
|
min_level => DEBUG ? 'debug' : 'info', |
69
|
|
|
|
|
|
|
max_level => 'warning', |
70
|
|
|
|
|
|
|
newline => 1, |
71
|
|
|
|
|
|
|
utf8 => 0, |
72
|
|
|
|
|
|
|
stderr => 0, |
73
|
|
|
|
|
|
|
use_color => 1, |
74
|
|
|
|
|
|
|
], |
75
|
|
|
|
|
|
|
[ |
76
|
|
|
|
|
|
|
'Screen', |
77
|
|
|
|
|
|
|
name => 'screen-error', |
78
|
|
|
|
|
|
|
min_level => 'error', |
79
|
|
|
|
|
|
|
newline => 1, |
80
|
|
|
|
|
|
|
utf8 => 0, |
81
|
|
|
|
|
|
|
stderr => 1, |
82
|
|
|
|
|
|
|
use_color => 1, |
83
|
|
|
|
|
|
|
], |
84
|
|
|
|
|
|
|
[ |
85
|
|
|
|
|
|
|
'File', |
86
|
|
|
|
|
|
|
name => 'file-01', |
87
|
|
|
|
|
|
|
filename => $logDirectory . $logFilename, |
88
|
|
|
|
|
|
|
min_level => DEBUG ? 'debug' : 'info', |
89
|
|
|
|
|
|
|
newline => 1, |
90
|
|
|
|
|
|
|
mode => 'append', |
91
|
|
|
|
|
|
|
binmode => ':encoding(UTF-8)', |
92
|
|
|
|
|
|
|
], |
93
|
|
|
|
|
|
|
], |
94
|
|
|
|
|
|
|
callbacks => [ |
95
|
|
|
|
|
|
|
sub { |
96
|
|
|
|
|
|
|
my %msg = @_; |
97
|
|
|
|
|
|
|
my $i = 0; |
98
|
|
|
|
|
|
|
my @array_caller; |
99
|
|
|
|
|
|
|
my ( $package, $filename, $line, $subroutine, $hasargs, $wantarray, $evaltext, $is_require, $hints, $bitmask, $hinthash ); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
do |
102
|
|
|
|
|
|
|
{ |
103
|
|
|
|
|
|
|
( $package, $filename, $line, $subroutine, $hasargs, $wantarray, $evaltext, $is_require, $hints, $bitmask, $hinthash ) = caller( $i++ ); |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
my $auxiliar = { |
106
|
|
|
|
|
|
|
package => $package, |
107
|
|
|
|
|
|
|
filename => $filename, |
108
|
|
|
|
|
|
|
line => $line, |
109
|
|
|
|
|
|
|
subroutine => $subroutine, |
110
|
|
|
|
|
|
|
}; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
push( @array_caller, $auxiliar ); |
113
|
|
|
|
|
|
|
} until ( !defined $line or $line == 0 or $subroutine =~ /(eval)/ ); |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
$msg{ message } =~ s/\n|\r//g; |
116
|
|
|
|
|
|
|
my $mensage = sprintf( "%s [ %9.9s ] [ pid: %d ] - %s - [ %s ]", strftime( "%F %H:%M:%S", localtime ), uc( $msg{ level } ), $$, $msg{ message }, $array_caller[ -2 ]->{ subroutine } ); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
return $mensage; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
] |
121
|
|
|
|
|
|
|
); |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Log::Any::Adapter->set( 'Dispatch', dispatcher => $dispatcher ); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub import |
127
|
|
|
|
|
|
|
{ |
128
|
1
|
|
|
1
|
|
9
|
my ( $self, $parameters ) = @_; |
129
|
1
|
|
|
|
|
12
|
my $caller = caller(); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
#################### main pod documentation begin ################### |
133
|
|
|
|
|
|
|
## Below is the stub of documentation for your module. |
134
|
|
|
|
|
|
|
## You better edit it! |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=pod |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=encoding UTF-8 |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 NAME |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Siffra::Logger - Siffra config for C<Log::Any> |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 SYNOPSIS |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
In a CPAN or other module: |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
package Foo; |
149
|
|
|
|
|
|
|
use Log::Any qw($log); |
150
|
|
|
|
|
|
|
use Siffra::Logger; |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
# log a string |
153
|
|
|
|
|
|
|
$log->error("an error occurred"); |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
# log a string and some data |
156
|
|
|
|
|
|
|
$log->info("program started", {progname => $0, pid => $$, perl_version => $]}); |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
# log a string and data using a format string |
159
|
|
|
|
|
|
|
$log->debugf("arguments are: %s", \@_); |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
# log an error and throw an exception |
162
|
|
|
|
|
|
|
die $log->fatal("a fatal error occurred"); |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
In your application: |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
use Foo; |
167
|
|
|
|
|
|
|
use Log::Any qw($log); |
168
|
|
|
|
|
|
|
use Siffra::Logger; |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
# log a string |
171
|
|
|
|
|
|
|
$log->error("an error occurred"); |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
# log a string and some data |
174
|
|
|
|
|
|
|
$log->info("program started", {progname => $0, pid => $$, perl_version => $]}); |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
# log a string and data using a format string |
177
|
|
|
|
|
|
|
$log->debugf("arguments are: %s", \@_); |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
# log an error and throw an exception |
180
|
|
|
|
|
|
|
die $log->fatal("a fatal error occurred"); |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head2 OUTPUTS |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=over 12 |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=item C<Directory Creation> |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
my ( $filename, $baseDirectory, $suffix ) = fileparse( $0, qr/\.[^.]*/ ); |
189
|
|
|
|
|
|
|
my $logDirectory = $baseDirectory . 'logs/'; |
190
|
|
|
|
|
|
|
my $logFilename = $filename . '.log'; |
191
|
|
|
|
|
|
|
croak( "Unable to create $logDirectory" ) unless ( -e $logDirectory or mkdir $logDirectory ); |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=item C<Outputs> |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
[ |
196
|
|
|
|
|
|
|
'Screen', |
197
|
|
|
|
|
|
|
name => 'screen', |
198
|
|
|
|
|
|
|
min_level => 'debug', |
199
|
|
|
|
|
|
|
max_level => 'warning', |
200
|
|
|
|
|
|
|
newline => 1, |
201
|
|
|
|
|
|
|
utf8 => 0, |
202
|
|
|
|
|
|
|
stderr => 0, |
203
|
|
|
|
|
|
|
use_color => 1, |
204
|
|
|
|
|
|
|
], |
205
|
|
|
|
|
|
|
[ |
206
|
|
|
|
|
|
|
'Screen', |
207
|
|
|
|
|
|
|
name => 'screen-error', |
208
|
|
|
|
|
|
|
min_level => 'error', |
209
|
|
|
|
|
|
|
newline => 1, |
210
|
|
|
|
|
|
|
utf8 => 0, |
211
|
|
|
|
|
|
|
stderr => 1, |
212
|
|
|
|
|
|
|
use_color => 1, |
213
|
|
|
|
|
|
|
], |
214
|
|
|
|
|
|
|
[ |
215
|
|
|
|
|
|
|
'File', |
216
|
|
|
|
|
|
|
name => 'file-01', |
217
|
|
|
|
|
|
|
filename => $logDirectory . $logFilename, |
218
|
|
|
|
|
|
|
min_level => 'debug', |
219
|
|
|
|
|
|
|
newline => 1, |
220
|
|
|
|
|
|
|
mode => 'write', |
221
|
|
|
|
|
|
|
binmode => ':encoding(UTF-8)', |
222
|
|
|
|
|
|
|
] |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=back |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=head1 DESCRIPTION |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
C<Siffra::logger> provides a standart outputs to C<Log::Any> |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=head1 AUTHOR |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
Luiz Benevenuto |
233
|
|
|
|
|
|
|
CPAN ID: LUIZBENE |
234
|
|
|
|
|
|
|
Siffra TI |
235
|
|
|
|
|
|
|
luiz@siffra.com.br |
236
|
|
|
|
|
|
|
https://siffra.com.br |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=head1 COPYRIGHT |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
This program is free software; you can redistribute |
241
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
The full text of the license can be found in the |
244
|
|
|
|
|
|
|
LICENSE file included with this module. |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=head1 SEE ALSO |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
perl(1). |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=cut |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
#################### main pod documentation end ################### |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
1; |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
# The preceding line will help the module return a true value |
257
|
|
|
|
|
|
|
|