line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
642
|
use 5.008001; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
30
|
|
2
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
31
|
|
3
|
1
|
|
|
1
|
|
11
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
49
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Log::Any::Adapter::Redis; |
6
|
|
|
|
|
|
|
$Log::Any::Adapter::Redis::VERSION = '0.004'; |
7
|
|
|
|
|
|
|
# ABSTRACT: Simple adapter for logging to redis |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
4
|
use Log::Any::Adapter::Util (); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
14
|
|
10
|
1
|
|
|
1
|
|
565
|
use RedisDB; |
|
1
|
|
|
|
|
52434
|
|
|
1
|
|
|
|
|
33
|
|
11
|
1
|
|
|
1
|
|
537
|
use Sys::Hostname; |
|
1
|
|
|
|
|
936
|
|
|
1
|
|
|
|
|
50
|
|
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
5
|
use base qw/Log::Any::Adapter::Base/; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
231
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $trace_level = Log::Any::Adapter::Util::numeric_level('trace'); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
18
|
1
|
|
|
1
|
0
|
758
|
my ( $class, @args ) = @_; |
19
|
1
|
|
|
|
|
8
|
return $class->SUPER::new( |
20
|
|
|
|
|
|
|
host => 'localhost', |
21
|
|
|
|
|
|
|
port => 6379, |
22
|
|
|
|
|
|
|
database => 0, |
23
|
|
|
|
|
|
|
ignore_reply => 0, |
24
|
|
|
|
|
|
|
log_level => $trace_level, |
25
|
|
|
|
|
|
|
log_hostname => 0, |
26
|
|
|
|
|
|
|
log_pid => 0, |
27
|
|
|
|
|
|
|
@args |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub init { |
32
|
1
|
|
|
1
|
0
|
10
|
my $self = shift; |
33
|
1
|
50
|
|
|
|
8
|
$self->{log_level} = Log::Any::Adapter::Util::numeric_level( $self->{log_level} ) |
34
|
|
|
|
|
|
|
unless $self->{log_level} =~ /^\d+$/; |
35
|
1
|
50
|
33
|
|
|
9
|
if ( !exists $self->{redis_db} || ref( $self->{redis_db} ) ne 'RedisDB' ) { |
36
|
0
|
|
|
|
|
|
$self->{redis_db} = RedisDB->new( |
37
|
|
|
|
|
|
|
host => $self->{host}, |
38
|
|
|
|
|
|
|
port => $self->{port}, |
39
|
|
|
|
|
|
|
database => $self->{database} |
40
|
|
|
|
|
|
|
); |
41
|
0
|
0
|
|
|
|
|
$self->{key} = 'LOG' if !exists $self->{key}; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
foreach my $method ( Log::Any::Adapter::Util::logging_methods() ) { |
46
|
1
|
|
|
1
|
|
5
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
192
|
|
47
|
|
|
|
|
|
|
my $method_level = Log::Any::Adapter::Util::numeric_level($method); |
48
|
|
|
|
|
|
|
*{$method} = sub { |
49
|
0
|
|
|
0
|
|
|
my ( $self, $text ) = @_; |
50
|
0
|
0
|
|
|
|
|
return if $method_level > $self->{log_level}; |
51
|
0
|
|
|
|
|
|
my $msg = sprintf( "[%s]", scalar(localtime) ); |
52
|
0
|
0
|
|
|
|
|
$msg .= sprintf( "[%s]", hostname() ) if $self->{log_hostname}; |
53
|
0
|
0
|
|
|
|
|
$msg .= sprintf( "[%s]", $$ ) if $self->{log_pid}; |
54
|
0
|
|
|
|
|
|
$msg .= sprintf( " %s", $text ); |
55
|
0
|
0
|
|
|
|
|
if ( $self->{ignore_reply} ) { |
56
|
0
|
|
|
|
|
|
$self->{redis_db}->send_command( 'rpush', $self->{key}, $msg, RedisDB::IGNORE_REPLY ); |
57
|
|
|
|
|
|
|
} else { |
58
|
0
|
|
|
|
|
|
$self->{redis_db}->rpush( $self->{key}, $msg ); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
}; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
foreach my $method ( Log::Any::Adapter::Util::detection_methods() ) { |
64
|
1
|
|
|
1
|
|
5
|
no strict 'refs'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
82
|
|
65
|
|
|
|
|
|
|
my $base = substr( $method, 3 ); |
66
|
|
|
|
|
|
|
my $method_level = Log::Any::Adapter::Util::numeric_level($base); |
67
|
|
|
|
|
|
|
*{$method} = sub { |
68
|
0
|
|
|
0
|
|
|
return !!( $method_level <= $_[0]->{log_level} ); |
69
|
|
|
|
|
|
|
}; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
!0; # 3a59124cfcc7ce26274174c962094a20 |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
__END__ |