File Coverage

blib/lib/Net/DRI/Logging/Syslog.pm
Criterion Covered Total %
statement 15 45 33.3
branch 0 18 0.0
condition 0 21 0.0
subroutine 5 10 50.0
pod 4 4 100.0
total 24 98 24.4


line stmt bran cond sub pod time code
1             ## Domain Registry Interface, SYSLOG Logging operations for Net::DRI
2             ##
3             ## Copyright (c) 2009,2013,2014 Jørgen Thomsen . All rights reserved
4             ##
5             ## This file is part of Net::DRI
6             ##
7             ## Net::DRI is free software; you can redistribute it and/or modify
8             ## it under the terms of the GNU General Public License as published by
9             ## the Free Software Foundation; either version 2 of the License, or
10             ## (at your option) any later version.
11             ##
12             ## See the LICENSE file that comes with this distribution for more details.
13             ####################################################################################################
14              
15             package Net::DRI::Logging::Syslog;
16              
17 1     1   23424 use utf8;
  1         3  
  1         10  
18 1     1   39 use strict;
  1         3  
  1         48  
19 1     1   7 use warnings;
  1         2  
  1         53  
20              
21 1     1   8 use base qw/Net::DRI::Logging/;
  1         3  
  1         647  
22              
23 1     1   9 use Sys::Syslog qw(:DEFAULT);
  1         2  
  1         855  
24              
25             ####################################################################################################
26              
27             sub new
28             {
29 0     0 1   my ($class,$data)=@_;
30 0           my $self=$class->SUPER::new($data);
31 0 0 0       if (! exists $self->{ident} || ! defined $self->{ident} ) { $self->{ident} = 'NetDRI'; }
  0            
32 0 0 0       if (! exists $self->{priority} || ! defined $self->{priority} ) { $self->{priority} = 'info'; }
  0            
33 0 0 0       if (! exists $self->{options} || ! defined $self->{options} ) { $self->{options} = 'pid,nofatal'; }
  0            
34 0 0 0       if (! exists $self->{facility} || ! defined $self->{facility} ) { $self->{facility} = 'local3'; }
  0            
35 0 0 0       if (! exists $self->{logopened} || ! defined $self->{logopened} ) { $self->{logopened} = 0; }
  0            
36 0           return $self;
37             }
38              
39 0     0 1   sub name { return 'syslog'; }
40              
41             sub setup_channel {
42 0     0 1   my ($self,$source,$type,$data)=@_;
43 0           $self->{format_header} ='[%ULEVEL] <%TYPE>';
44             # either opened by caller: 1 or opened here: 2
45 0 0 0       if (exists $self->{logopened} && defined($self->{logopened}) && $self->{logopened} > 0) { return; }
  0   0        
46              
47 0           openlog($self->{ident}, $self->{options}, $self->{facility});
48 0           $self->{logopened} = 2;
49 0           return;
50             }
51              
52             sub output
53             {
54 0     0 1   my ($self,$level,$type,$data)=@_;
55 0 0         if ($self->should_log($level)) {
56 0           my @lines = split( /\n/, $self->tostring($level,$type,$data) ); # log each indented line when xml_indent => 1
57 0           foreach (@lines) {
58 0 0         syslog($self->{priority}, ($self->{logopened} != 2 ? $self->{ident}.': ':'')."%s", $_);
59             }
60             }
61 0           return;
62             }
63              
64             sub DESTROY
65             {
66 0     0     my ($self)=@_;
67 0 0         closelog() if $self->{logopened} == 2; # we opened it
68 0           return;
69             }
70             ####################################################################################################
71             1;
72              
73             __END__