line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Spike::Log; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
3
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
20
|
|
4
|
1
|
|
|
1
|
|
2
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
19
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
394
|
use POSIX qw(strftime); |
|
1
|
|
|
|
|
4064
|
|
|
1
|
|
|
|
|
3
|
|
7
|
1
|
|
|
1
|
|
1218
|
use Time::HiRes; |
|
1
|
|
|
|
|
916
|
|
|
1
|
|
|
|
|
2
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $time_format = '%Y-%m-%d %H:%M:#S'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $log_format = '%2$s [%3$s] %1$s'; |
12
|
|
|
|
|
|
|
our $log_bind = ']['; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $bind_values = undef; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub format_time { |
17
|
0
|
|
0
|
0
|
0
|
|
my $time = shift // Time::HiRes::time(); |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
my $i_time = int $time; |
20
|
0
|
|
|
|
|
|
my $f_time = $time - $i_time; |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
my @time = localtime $i_time; |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
(my $format = $time_format) =~ s!#S!sprintf("%07.4f", $time[0] + $f_time)!e; |
|
0
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
return strftime($format, @time); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
0
|
0
|
|
0
|
0
|
|
sub format_log { sprintf($log_format, $_[0], format_time, join($log_bind, @{$bind_values || [$$]})) } |
|
0
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
$SIG{__WARN__} = sub { warn format_log($_[0]) }; |
32
|
|
|
|
|
|
|
$SIG{__DIE__} = sub { die ref $_[0] ? $_[0] : format_log($_[0]) if $^S }; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
1; |