| 1 | package Log::Dispatch::Syslog; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | our $VERSION = '2.71'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Log::Dispatch::Types; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Params::ValidationCompiler qw( validation_for ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Scalar::Util qw( reftype ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Sys::Syslog 0.28 (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use base qw( Log::Dispatch::Output ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 2 | my $thread_lock; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | { | ||||||||||||||||||||||||||||
| 19 | 2 | my ($DefaultIdent) = $0 =~ /(.+)/; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 2 | my $validator = validation_for( | |||||||||||||||||||||||||||
| 22 | params => { | ||||||||||||||||||||||||||||
| 23 | ident => { | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | # It's weird to allow an empty string but that's how this | ||||||||||||||||||||||||||||
| 26 | # worked pre-PVC. | ||||||||||||||||||||||||||||
| 27 | type => t('Str'), | ||||||||||||||||||||||||||||
| 28 | default => $DefaultIdent | ||||||||||||||||||||||||||||
| 29 | }, | ||||||||||||||||||||||||||||
| 30 | logopt => { | ||||||||||||||||||||||||||||
| 31 | type => t('Str'), | ||||||||||||||||||||||||||||
| 32 | default => q{}, | ||||||||||||||||||||||||||||
| 33 | }, | ||||||||||||||||||||||||||||
| 34 | facility => { | ||||||||||||||||||||||||||||
| 35 | type => t('NonEmptyStr'), | ||||||||||||||||||||||||||||
| 36 | default => 'user' | ||||||||||||||||||||||||||||
| 37 | }, | ||||||||||||||||||||||||||||
| 38 | socket => { | ||||||||||||||||||||||||||||
| 39 | type => t('SyslogSocket'), | ||||||||||||||||||||||||||||
| 40 | default => undef, | ||||||||||||||||||||||||||||
| 41 | }, | ||||||||||||||||||||||||||||
| 42 | lock => { | ||||||||||||||||||||||||||||
| 43 | type => t('Bool'), | ||||||||||||||||||||||||||||
| 44 | default => 0, | ||||||||||||||||||||||||||||
| 45 | }, | ||||||||||||||||||||||||||||
| 46 | }, | ||||||||||||||||||||||||||||
| 47 | slurpy => 1, | ||||||||||||||||||||||||||||
| 48 | ); | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 2 | my $threads_loaded; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 3 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=19.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 53 | 3 | my $class = shift; | |||||||||||||||||||||||||||
| 54 | 3 | my %p = $validator->(@_); | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 3 | my $self = bless { map { $_ => delete $p{$_} } | |||||||||||||||||||||||||||
| 57 | qw( ident logopt facility socket lock ) }, | ||||||||||||||||||||||||||||
| 58 | $class; | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 3 | ▶ | if ( $self->{lock} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 0 | ▶ | unless ($threads_loaded) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 0 | local ( $@, $SIG{__DIE__} ) = ( undef, undef ); | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | ## no critic (BuiltinFunctions::ProhibitStringyEval) | ||||||||||||||||||||||||||||
| 65 | # These need to be loaded with use, not require. | ||||||||||||||||||||||||||||
| 66 | 0 | ▶ | die $@ unless eval 'use threads; use threads::shared; 1;'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 0 | $threads_loaded = 1; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | 0 | &threads::shared::share( \$thread_lock ); | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 3 | $self->_basic_init(%p); | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 3 | return $self; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | { | ||||||||||||||||||||||||||||
| 79 | 2 | my @priorities = ( | |||||||||||||||||||||||||||
| 80 | 'DEBUG', | ||||||||||||||||||||||||||||
| 81 | 'INFO', | ||||||||||||||||||||||||||||
| 82 | 'NOTICE', | ||||||||||||||||||||||||||||
| 83 | 'WARNING', | ||||||||||||||||||||||||||||
| 84 | 'ERR', | ||||||||||||||||||||||||||||
| 85 | 'CRIT', | ||||||||||||||||||||||||||||
| 86 | 'ALERT', | ||||||||||||||||||||||||||||
| 87 | 'EMERG', | ||||||||||||||||||||||||||||
| 88 | ); | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 3 | ▶ | sub log_message { | ||||||||||||||||||||||||||
|
Subroutine
log_message: called CC=5 SCAR=19.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 91 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 92 | 3 | my %p = @_; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 3 | my $pri = $self->_level_as_number( $p{level} ); | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 3 | ▶ | lock($thread_lock) if $self->{lock}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | return | ||||||||||||||||||||||||||||
| 99 | 3 | ▶ | if try { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.8
| |||||||||||||||||||||||||||||
| 100 | 3 | ▶ | if ( defined $self->{socket} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | Sys::Syslog::setlogsock( | ||||||||||||||||||||||||||||
| 102 | ref $self->{socket} | ||||||||||||||||||||||||||||
| 103 | && reftype( $self->{socket} ) eq 'ARRAY' | ||||||||||||||||||||||||||||
| 104 | 0 | ? @{ $self->{socket} } | |||||||||||||||||||||||||||
| 105 | : $self->{socket} | ||||||||||||||||||||||||||||
| 106 | 2 | ▶ | ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $self->{"socket"} and builtin::reftype($self->{"socket"}) eq "ARRAY"
MC/DC0%0/2
ref $self->{"socket"} and builtin::reftype($self->{"socket"}) eq "ARRAY"
ref $self->{"socket"}
builtin::reftype($self->{"socket"}) eq "ARRAY"
Truth table33%1/3
A and B
A= ref $self->{"socket"}B= builtin::reftype($self->{"socket"}) eq "ARRAY"
| |||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | Sys::Syslog::openlog( | ||||||||||||||||||||||||||||
| 110 | $self->{ident}, | ||||||||||||||||||||||||||||
| 111 | $self->{logopt}, | ||||||||||||||||||||||||||||
| 112 | $self->{facility} | ||||||||||||||||||||||||||||
| 113 | 3 | ); | |||||||||||||||||||||||||||
| 114 | 3 | Sys::Syslog::syslog( $priorities[$pri], $p{message} ); | |||||||||||||||||||||||||||
| 115 | 3 | Sys::Syslog::closelog(); | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 3 | 1; | |||||||||||||||||||||||||||
| 118 | 3 | ▶ | }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 0 | ▶ | warn $@ if $@ and $^W; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$@ and $^W
MC/DC0%0/2
$@ and $^W
$@
$^W
Truth table0%0/3
A and B
A= $@B= $^W
| |||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 2 | 1; | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | # ABSTRACT: Object for logging to system log. | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | __END__ | ||||||||||||||||||||||||||||