line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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 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 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
|
|
|
1
|
|
34288
|
use base qw /Exporter/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
123
|
|
38
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
27
|
|
39
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
404
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
our $VERSION = 0.1; |
56
|
|
|
|
|
|
|
our $BASE_DIR = $ENV{LOGGER_BASEDIR} || "/var/log/synapse/"; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub base_dir { |
61
|
2
|
50
|
|
2
|
0
|
39
|
-e $BASE_DIR or mkdir $BASE_DIR; |
62
|
2
|
|
|
|
|
9
|
return $BASE_DIR; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub logname { |
67
|
2
|
|
|
2
|
0
|
5
|
local $_ = $0; |
68
|
2
|
|
|
|
|
15
|
s/[^a-z0-9]/-/gi; |
69
|
2
|
|
|
|
|
12
|
s/\-+/-/g; |
70
|
2
|
|
|
|
|
4
|
s/^\-//; |
71
|
2
|
|
|
|
|
3
|
s/\-$//; |
72
|
2
|
|
|
|
|
7
|
return $_; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 logger($message) |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Exported function that logs stuff. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=cut |
81
|
|
|
|
|
|
|
sub logger { |
82
|
2
|
50
|
|
2
|
1
|
20
|
my ($logname, $message) = @_ == 1 ? (Synapse::Logger::logname(), shift()) : @_; |
83
|
2
|
|
|
|
|
7
|
my $file = Synapse::Logger::base_dir() . "/$logname.log"; |
84
|
2
|
|
|
|
|
30
|
my $date = scalar gmtime; |
85
|
2
|
50
|
|
|
|
76
|
open LOGFILE, ">>$file" or return; |
86
|
2
|
|
|
|
|
25
|
print LOGFILE "$date\t$message\n"; |
87
|
2
|
|
|
|
|
78
|
close LOGFILE; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
__END__ |