lib/Synapse/Logger.pm

filter: Statementstmt 100% 27 / 27 Branchbran 66.6% 4 / 6 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 6 / 6 Podpod 33.3% 1 / 3 totaltotal 86.6% 39 / 45 CC 4 SCAR 6.5
CC
4
Cov
91%
logger
3.1
base_dir
2.0
BEGIN
1.0
CRAP 1.9
↑ Summary
1 =head1 NAME
2  
3 Synapse::CLI::Logger - yet another logging mechanism
4  
5  
6 =head1 About Synapse's Open Telephony Toolkit
7  
8 L<Synapse::Logger> is a part of Synapse's Wholesale Open Telephony
9 Toolkit.
10  
11 As we are refactoring our codebase, we at Synapse have decided to release a
12 substantial portion of our code under the GPL. We hope that as a developer, you
13 will find it as useful as we have found open source and CPAN to be of use to
14 us.
15  
16  
17 =head1 What is L<Synapse::Logger> all about
18  
19 Does what it says on the tin.
20  
21  
22 =head1 SYNOPSIS
23  
24 use Synapse::Logger;
25 logger ("some stuff"); # uses $0 as logname...
26 logger (logname => "some stuff"); # specifies logname...
27  
28 Or on the command-line
29  
30 synapse-logger logname "some stuff"
31  
32  
33 =head1 API
34  
35 =cut
36 package Synapse::Logger;
37 1 ▶use base qw /Exporter/;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 1 our @EXPORT = qw(logger);
42  
43  
44 =head2 GLOBALS
45  
46 =over 4
47  
48 =item $Synapse::Logger::VERSION - library version number
49  
50 =item $Synapse::Logger::BASE_DIR - points to the directory where logfiles live.
51  
52 =back
53  
54 =cut
55 1 our $VERSION = 0.1;
56 1 ▶our $BASE_DIR = $ENV{LOGGER_BASEDIR} || "/var/log/synapse/";
Condition50%1/2
$ENV{'LOGGER_BASEDIR'} || '/var/log/synapse/'
l!l
01
MC/DC0%0/1
$ENV{'LOGGER_BASEDIR'} || '/var/log/synapse/'
$ENV{'LOGGER_BASEDIR'}
Truth table50%1/2
A
A= $ENV{'LOGGER_BASEDIR'}
Aresult
11
00
57  
58  
59  
60 2 ▶sub base_dir {
Subroutine base_dir: called CC=2 SCAR=6.9
Pod undocumented
61 2 ▶ -e $BASE_DIR or mkdir $BASE_DIR;
Branch: 1 branch
BranchTrueFalseTotal
-e $Synapse::Logger::BASE_DIR or mkdir $Synapse::Logger::BASE_DIR 1 1 2
62 2 return $BASE_DIR;
63 }
64  
65  
66 2 ▶sub logname {
Subroutine logname: called CC=1 SCAR=0.0
Pod undocumented
67 2 local $_ = $0;
68 2 s/[^a-z0-9]/-/gi;
69 2 s/\-+/-/g;
70 2 s/^\-//;
71 2 s/\-$//;
72 2 return $_;
73 }
74  
75  
76 =head2 logger($message)
77  
78 Exported function that logs stuff.
79  
80 =cut
81 2 ▶sub logger {
Subroutine logger: called CC=3 SCAR=11.2
Pod documented
82 2 ▶ my ($logname, $message) = @_ == 1 ? (Synapse::Logger::logname(), shift()) : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 2 0 2
83 2 my $file = Synapse::Logger::base_dir() . "/$logname.log";
84 2 my $date = scalar gmtime;
85 2 ▶ open LOGFILE, ">>$file" or return;
Branch: 1 branch
BranchTrueFalseTotal
open LOGFILE, ">>$file" or return 2 0 2
86 2 print LOGFILE "$date\t$message\n";
87 2 close LOGFILE;
88 }
89  
90  
91  
92 1 1;
93  
94  
95 __END__
↑ Summary