| 1 | ## | ||||||||||||||
| 2 | ## Schedule::Chronic::Logger | ||||||||||||||
| 3 | ## Author: Vipul Ved Prakash <mail@vipul.net>. | ||||||||||||||
| 4 | ## $Id: Logger.pm,v 1.2 2004/07/26 23:12:49 hackworth Exp $ | ||||||||||||||
| 5 | ## | ||||||||||||||
| 6 | |||||||||||||||
| 7 | package Schedule::Chronic::Logger; | ||||||||||||||
| 8 | 1 | ▶ | use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 1 | ▶ | use Errno qw(:POSIX); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 1 | ▶ | use Data::Dumper; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 1 | ▶ | use Sys::Syslog qw(:DEFAULT setlogsock); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | |||||||||||||||
| 13 | # Preloaded methods go here. | ||||||||||||||
| 14 | |||||||||||||||
| 15 | 0 | ▶ | sub new { | ||||||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||
| 16 | |||||||||||||||
| 17 | 0 | my ($class, %args) = @_; | |||||||||||||
| 18 | |||||||||||||||
| 19 | 0 | my %self = (%args); | |||||||||||||
| 20 | |||||||||||||||
| 21 | 0 | ▶ | $self{facility} ||= 'daemon'; | ||||||||||||
|
Condition0%0/2
$self{"facility"} ||= "daemon"
MC/DC0%0/1
$self{"facility"} ||= "daemon"
$self{"facility"}
Truth table0%0/2
A
A= $self{"facility"}
| |||||||||||||||
| 22 | 0 | ▶ | $self{name} ||= 'Chronic'; | ||||||||||||
|
Condition0%0/2
$self{"name"} ||= "Chronic"
MC/DC0%0/1
$self{"name"} ||= "Chronic"
$self{"name"}
Truth table0%0/2
A
A= $self{"name"}
| |||||||||||||||
| 23 | |||||||||||||||
| 24 | # Open a connection to syslog over a UNIX socket. | ||||||||||||||
| 25 | 0 | ▶ | if ($args{type} eq 'syslog') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 26 | |||||||||||||||
| 27 | 0 | openlog('Chronic', 'cons,pid', 'user'); | |||||||||||||
| 28 | 0 | setlogsock('unix'); | |||||||||||||
| 29 | |||||||||||||||
| 30 | } | ||||||||||||||
| 31 | |||||||||||||||
| 32 | # Syslog priorities and facilities. These are also used with | ||||||||||||||
| 33 | # logging to STDERR. | ||||||||||||||
| 34 | $self{syslog_priorities} = { | ||||||||||||||
| 35 | |||||||||||||||
| 36 | 0 | emerg => 0, | |||||||||||||
| 37 | alert => 1, | ||||||||||||||
| 38 | crit => 2, | ||||||||||||||
| 39 | err => 3, | ||||||||||||||
| 40 | warning => 4, | ||||||||||||||
| 41 | notice => 5, | ||||||||||||||
| 42 | info => 6, | ||||||||||||||
| 43 | debug => 7 | ||||||||||||||
| 44 | |||||||||||||||
| 45 | }; | ||||||||||||||
| 46 | |||||||||||||||
| 47 | $self{syslog_facilities} = { | ||||||||||||||
| 48 | |||||||||||||||
| 49 | 0 | kern => 0, | |||||||||||||
| 50 | user => 1, | ||||||||||||||
| 51 | mail => 2, | ||||||||||||||
| 52 | daemon => 3, | ||||||||||||||
| 53 | auth => 4, | ||||||||||||||
| 54 | syslog => 5, | ||||||||||||||
| 55 | lpr => 6, | ||||||||||||||
| 56 | news => 7, | ||||||||||||||
| 57 | uucp => 8, | ||||||||||||||
| 58 | cron => 9, | ||||||||||||||
| 59 | authpriv=> 10, | ||||||||||||||
| 60 | ftp => 11, | ||||||||||||||
| 61 | local0 => 16, | ||||||||||||||
| 62 | local1 => 17, | ||||||||||||||
| 63 | local2 => 18, | ||||||||||||||
| 64 | local3 => 19, | ||||||||||||||
| 65 | local4 => 20, | ||||||||||||||
| 66 | local5 => 21, | ||||||||||||||
| 67 | local6 => 22, | ||||||||||||||
| 68 | |||||||||||||||
| 69 | }; | ||||||||||||||
| 70 | |||||||||||||||
| 71 | 0 | return bless \%self, $class; | |||||||||||||
| 72 | |||||||||||||||
| 73 | } | ||||||||||||||
| 74 | |||||||||||||||
| 75 | |||||||||||||||
| 76 | 0 | ▶ | sub logthis { | ||||||||||||
|
Subroutine
logthis: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||
| 77 | |||||||||||||||
| 78 | 0 | my ($self, $msg, $prio) = @_; | |||||||||||||
| 79 | |||||||||||||||
| 80 | # Default priority is 'debug' | ||||||||||||||
| 81 | 0 | ▶ | $prio ||= 'debug'; | ||||||||||||
|
Condition0%0/2
$prio ||= "debug"
MC/DC0%0/1
$prio ||= "debug"
$prio
Truth table0%0/2
A
A= $prio
| |||||||||||||||
| 82 | |||||||||||||||
| 83 | 0 | ▶ | if ($$self{type} eq 'syslog') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 84 | |||||||||||||||
| 85 | 0 | syslog("$$self{facility}|$prio", $msg); | |||||||||||||
| 86 | |||||||||||||||
| 87 | } elsif ($$self{type} eq 'stderr') { | ||||||||||||||
| 88 | 0 | $msg =~ s/^.+?:://; | |||||||||||||
| 89 | 0 | print STDERR "debug: $msg\n"; | |||||||||||||
| 90 | } | ||||||||||||||
| 91 | |||||||||||||||
| 92 | } | ||||||||||||||
| 93 | |||||||||||||||
| 94 | |||||||||||||||
| 95 | 1 | 1; | |||||||||||||