| 1 | package Dancer2::Logger::Fluent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use 5.008_005; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | our $VERSION = '0.06'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Fluent::Logger; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use IO::Socket::INET; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use IO::Socket::UNIX; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use File::Basename 'basename'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use Time::Moment; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use Sys::Hostname; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 3 | ▶ | use Dancer2::Core::Types; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | with 'Dancer2::Core::Role::Logger'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | has tag_prefix => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | isa => Str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | has host => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | isa => Str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | has port => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | isa => Str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 2 | has timeout => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | isa => Num, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | predicate => '_has_timeout', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 2 | has socket => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | isa => Str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 2 | has prefer_integer => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | isa => Str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | predicate => '_has_prefer_integer', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 2 | has event_time => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | isa => Bool, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 2 | has buffer_limit => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | isa => Int, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | predicate => '_has_buffer_limit', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 2 | has buffer_overflow_handler => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | isa => CodeRef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | predicate => '_has_buffer_overflow_handler', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 2 | has truncate_buffer_at_overflow => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | isa => Bool, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | ▶ | sub _build_tag_prefix { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_tag_prefix: called CC=4 SCAR=18.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 1 | ▶ | return $self->{tag_prefix} || $self->app_name || $ENV{DANCER_APPDIR} || basename($0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%3/9
$self->{'tag_prefix'} || $self->app_name || $ENV{'DANCER_APPDIR'} || basename($0)
$self->{"tag_prefix"} or $self->app_name or $ENV{"DANCER_APPDIR"}
$self->{"tag_prefix"} or $self->app_name
MC/DC0%0/4
$self->{'tag_prefix'} || $self->app_name || $ENV{'DANCER_APPDIR'} || basename($0)
$self->{"tag_prefix"}
$self->app_name
$ENV{"DANCER_APPDIR"}
basename($0)
Truth table20%1/5
A or B or C || D
A= $self->{"tag_prefix"}B= $self->app_nameC= $ENV{"DANCER_APPDIR"}D= basename($0)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 2 | ▶ | sub _connect { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_connect: called CC=5 SCAR=18.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 2 | ▶ | return defined $self->socket | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%2/4
$self->host || '127.0.0.1'
$self->port || 24224
MC/DC0%0/1
$self->host || '127.0.0.1'
$self->host
MC/DC0%0/1
$self->port || 24224
$self->port
Truth table50%1/2
A
A= $self->host
Truth table50%1/2
A
A= $self->port
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | ? IO::Socket::UNIX->new( Peer => $self->socket ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | : IO::Socket::INET->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | PeerAddr => $self->host || '127.0.0.1', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | PeerPort => $self->port || 24224, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | Proto => 'tcp', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | Timeout => $self->_has_timeout ? $self->timeout : 3.0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | ReuseAddr => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 2 | ▶ | sub _fluent { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fluent: called CC=11 SCAR=45.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 2 | ▶ | return unless $self->_connect; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | unless ( exists $self->{_fluent} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | $self->{_fluent} = Fluent::Logger->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | host => $self->host || '127.0.0.1', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | port => $self->port || 24224, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | timeout => $self->_has_timeout ? $self->timeout : 3.0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | socket => $self->socket, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | prefer_integer => $self->_has_prefer_integer ? $self->prefer_integer : 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | event_time => $self->event_time || 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | buffer_limit => $self->_has_buffer_limit ? $self->buffer_limit : 8388608, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | buffer_overflow_handler => $self->_has_buffer_overflow_handler ? $self->buffer_overflow_handler : sub { undef }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | truncate_buffer_at_overflow => $self->truncate_buffer_at_overflow || 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition0%0/8
$self->host || '127.0.0.1'
$self->port || 24224
$self->event_time || 0
$self->truncate_buffer_at_overflow || 0
MC/DC0%0/1
$self->host || '127.0.0.1'
$self->host
MC/DC0%0/1
$self->port || 24224
$self->port
MC/DC0%0/1
$self->event_time || 0
$self->event_time
MC/DC0%0/1
$self->truncate_buffer_at_overflow || 0
$self->truncate_buffer_at_overflow
Truth table0%0/2
A
A= $self->host
Truth table0%0/2
A
A= $self->port
Truth table0%0/2
A
A= $self->event_time
Truth table0%0/2
A
A= $self->truncate_buffer_at_overflow
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | return $self->{_fluent}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 1 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=3 SCAR=16.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 1 | ▶ | return unless $self->_fluent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | $self->_fluent->{pending} ||= ''; # Fluent::Logger->close performs length checks without checking if value is defined first | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->_fluent->{"pending"} ||= ""
MC/DC0%0/1
$self->_fluent->{"pending"} ||= ""
$self->_fluent->{"pending"}
Truth table0%0/2
A
A= $self->_fluent->{"pending"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | $self->_fluent->close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 1 | ▶ | sub log { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
log: called CC=7 SCAR=30.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 1 | my ($self, $level, $message) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | my $fluent_message = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 1 | ▶ | env => $ENV{DANCER_ENVIRONMENT} || $ENV{PLACK_ENV} || 'development', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
$ENV{'DANCER_ENVIRONMENT'} || $ENV{'PLACK_ENV'} || 'development'
$ENV{"DANCER_ENVIRONMENT"} or $ENV{"PLACK_ENV"}
MC/DC0%0/2
$ENV{'DANCER_ENVIRONMENT'} || $ENV{'PLACK_ENV'} || 'development'
$ENV{"DANCER_ENVIRONMENT"}
$ENV{"PLACK_ENV"}
Truth table33%1/3
A or B
A= $ENV{"DANCER_ENVIRONMENT"}B= $ENV{"PLACK_ENV"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | timestamp => Time::Moment->now_utc->strftime("%Y-%m-%dT%H:%M:%S.%6N%Z"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | host => hostname(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | level => $level, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | message => $message, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | pid => $$ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | # Queue pending messages until connectivity is restored | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 1 | ▶ | unless ( $self->_fluent ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 1 | push @{ $self->{pending} }, $fluent_message; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | if ( exists $self->{pending} and @{ $self->{pending} } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $self->{"pending"} and @{$self->{"pending"};}
MC/DC0%0/2
exists $self->{"pending"} and @{$self->{"pending"};}
exists $self->{"pending"}
@{$self->{"pending"};}
Truth table0%0/3
A and B
A= exists $self->{"pending"}B= @{$self->{"pending"};}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | while ( my $pending_message = shift @{ $self->{pending} } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | $self->_fluent->post( $self->tag_prefix, $pending_message ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | $self->_fluent->post( $self->tag_prefix, $fluent_message ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||