blib/lib/Log/Any/Adapter/Redis.pm

filter: Statementstmt 78.1% 43 / 55 Branchbran 14.2% 2 / 14 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 84.6% 11 / 13 Podpod 0.0% 0 / 2 totaltotal 64.0% 57 / 89 CC 9 SCAR 22.0
CC
9
Cov
64%
__ANON__
26.1
init
9.7
__ANON__
1.1
CRAP 9.0
↑ Summary
1 1 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Log::Any::Adapter::Redis;
6 1 $Log::Any::Adapter::Redis::VERSION = '1.000';
7 # ABSTRACT: Simple adapter for logging to redis
8  
9 1 ▶use Log::Any::Adapter::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use RedisDB;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Sys::Hostname;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use base qw/Log::Any::Adapter::Base/;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 my $trace_level = Log::Any::Adapter::Util::numeric_level('trace');
16  
17 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
18 1 my ( $class, @args ) = @_;
19 1 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 1 ▶sub init {
Subroutine init: called CC=5 SCAR=22.7
Pod undocumented
32 1 my $self = shift;
33 $self->{log_level} = Log::Any::Adapter::Util::numeric_level( $self->{log_level} )
34 1 ▶ unless $self->{log_level} =~ /^\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"log_level"} =~ /^\d+$/ 0 1 1
35 1 ▶ if ( !exists $self->{redis_db} || ref( $self->{redis_db} ) ne 'RedisDB' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $self->{"redis_db"} or ref $self->{"redis_db"} ne "RedisDB") 0 1 1
Condition33%1/3
not exists $self->{"redis_db"} or ref $self->{"redis_db"} ne "RedisDB"
l!l&&r!l&&!r
001
MC/DC0%0/2
not exists $self->{"redis_db"} or ref $self->{"redis_db"} ne "RedisDB"
not exists $self->{"redis_db"} ref $self->{"redis_db"} ne "RedisDB"
Truth table33%1/3
not(A) or B
A= not exists $self->{"redis_db"}B= ref $self->{"redis_db"} ne "RedisDB"
ABresult
1X1
011
000
36 $self->{redis_db} = RedisDB->new(
37 host => $self->{host},
38 port => $self->{port},
39 database => $self->{database}
40 0 );
41 0 ▶ $self->{key} = 'LOG' if !exists $self->{key};
Branch: 1 branch
BranchTrueFalseTotal
if not exists $self->{"key"} 0 0 0
42 }
43 }
44  
45 1 foreach my $method ( Log::Any::Adapter::Util::logging_methods() ) {
46 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
47 9 my $method_level = Log::Any::Adapter::Util::numeric_level($method);
48 9 ▶ *{$method} = sub {
Subroutine __ANON__: not called CC=5 SCAR=32.6
49 0 my ( $self, $text ) = @_;
50 0 ▶ return if $method_level > $self->{log_level};
Branch: 1 branch
BranchTrueFalseTotal
if $method_level > $self->{"log_level"} 0 0 0
51 0 my $msg = sprintf( "[%s]", scalar(localtime) );
52 0 ▶ $msg .= sprintf( "[%s]", hostname() ) if $self->{log_hostname};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log_hostname"} 0 0 0
53 0 ▶ $msg .= sprintf( "[%s]", $$ ) if $self->{log_pid};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"log_pid"} 0 0 0
54 0 $msg .= sprintf( " %s", $text );
55 0 ▶ if ( $self->{ignore_reply} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'ignore_reply'}) { } 0 0 0
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 9 };
61 }
62  
63 1 foreach my $method ( Log::Any::Adapter::Util::detection_methods() ) {
64 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
65 9 my $base = substr( $method, 3 );
66 9 my $method_level = Log::Any::Adapter::Util::numeric_level($base);
67 9 ▶ *{$method} = sub {
Subroutine __ANON__: not called CC=1 SCAR=1.2
68 0 return !!( $method_level <= $_[0]->{log_level} );
69 9 };
70 }
71  
72 1 !0; # 3a59124cfcc7ce26274174c962094a20
73  
74 __END__
↑ Summary