line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::FreeSWITCH::Line; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Pragmas. |
4
|
4
|
|
|
4
|
|
57878
|
use base qw(Exporter); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
345
|
|
5
|
4
|
|
|
4
|
|
19
|
use strict; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
82
|
|
6
|
4
|
|
|
4
|
|
20
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
108
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# Modules. |
9
|
4
|
|
|
4
|
|
2825
|
use Error::Pure qw(err); |
|
4
|
|
|
|
|
27696
|
|
|
4
|
|
|
|
|
79
|
|
10
|
4
|
|
|
4
|
|
2680
|
use Log::FreeSWITCH::Line::Data; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
116
|
|
11
|
4
|
|
|
4
|
|
24
|
use Readonly; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
198
|
|
12
|
4
|
|
|
4
|
|
21
|
use Scalar::Util qw(blessed); |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
1821
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# Constants. |
15
|
|
|
|
|
|
|
Readonly::Array our @EXPORT_OK => qw{parse serialize}; |
16
|
|
|
|
|
|
|
Readonly::Scalar our $LOG_REGEXP => qr{(\d{4}-\d{2}-\d{2})\s+(\d{2}:\d{2}:\d{2}\.?\d*)\s+\[(\w+)\]\s+([^:]+):(\d+)\s+(.*)}; |
17
|
|
|
|
|
|
|
Readonly::Scalar our $SPACE => q{ }; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Version. |
20
|
|
|
|
|
|
|
our $VERSION = 0.06; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Parse FreeSWITCH log line. |
23
|
|
|
|
|
|
|
sub parse { |
24
|
4
|
|
|
4
|
1
|
8061
|
my $data = shift; |
25
|
4
|
|
|
|
|
7
|
my $data_o; |
26
|
4
|
100
|
|
|
|
71
|
if ($data =~ m/^$LOG_REGEXP$/ms) { |
27
|
3
|
|
|
|
|
41
|
$data_o = Log::FreeSWITCH::Line::Data->new( |
28
|
|
|
|
|
|
|
'date' => $1, |
29
|
|
|
|
|
|
|
'file' => $4, |
30
|
|
|
|
|
|
|
'file_line' => $5, |
31
|
|
|
|
|
|
|
'message' => $6, |
32
|
|
|
|
|
|
|
'raw' => $data, |
33
|
|
|
|
|
|
|
'time' => $2, |
34
|
|
|
|
|
|
|
'type' => $3, |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
} else { |
37
|
1
|
|
|
|
|
7
|
err 'Cannot parse data.', |
38
|
|
|
|
|
|
|
'Data', $data; |
39
|
|
|
|
|
|
|
} |
40
|
3
|
|
|
|
|
230
|
return $data_o; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Serialize Log::FreeSWITCH::Line::Data object to FreeSWITCH log line. |
44
|
|
|
|
|
|
|
sub serialize { |
45
|
5
|
|
|
5
|
1
|
7459
|
my $data_o = shift; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# Check object. |
48
|
5
|
100
|
66
|
|
|
51
|
if (! blessed($data_o) || ! $data_o->isa('Log::FreeSWITCH::Line::Data')) { |
49
|
2
|
|
|
|
|
48
|
err "Serialize object must be 'Log::FreeSWITCH::Line::Data' object."; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# Serialize. |
53
|
3
|
|
|
|
|
14
|
my $data = $data_o->date. |
54
|
|
|
|
|
|
|
$SPACE.$data_o->time. |
55
|
|
|
|
|
|
|
$SPACE.'['.$data_o->type.']'. |
56
|
|
|
|
|
|
|
$SPACE.$data_o->file.':'.$data_o->file_line. |
57
|
|
|
|
|
|
|
$SPACE; |
58
|
3
|
100
|
|
|
|
118
|
if (defined $data_o->message) { |
59
|
2
|
|
|
|
|
18
|
$data .= $data_o->message; |
60
|
|
|
|
|
|
|
} |
61
|
3
|
|
|
|
|
29
|
$data_o->raw($data); |
62
|
3
|
|
|
|
|
27
|
return $data; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__END__ |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=pod |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=encoding utf8 |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 NAME |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Log::FreeSWITCH::Line - FreeSWITCH log line parsing and serializing. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 SYNOPSIS |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
use Log::FreeSWITCH::Line qw(parse serialize); |
80
|
|
|
|
|
|
|
my $data_o = parse($data); |
81
|
|
|
|
|
|
|
my $data = serialize($data_o); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 SUBROUTINES |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=over 8 |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=item C<parse($data)> |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Parse FreeSWITCH log line. |
90
|
|
|
|
|
|
|
Returns Log::FreeSWITCH::Line::Data object. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=item C<serialize($data_o)> |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Serialize Log::FreeSWITCH::Line::Data object to FreeSWITCH log line. |
95
|
|
|
|
|
|
|
Returns string. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=back |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 ERRORS |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
parse(): |
102
|
|
|
|
|
|
|
Cannot parse data. |
103
|
|
|
|
|
|
|
Data: %s |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
serialize(): |
106
|
|
|
|
|
|
|
Serialize object must be 'Log::FreeSWITCH::Line::Data' object. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 EXAMPLE1 |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# Pragmas. |
111
|
|
|
|
|
|
|
use strict; |
112
|
|
|
|
|
|
|
use warnings; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# Module. |
115
|
|
|
|
|
|
|
use Data::Printer; |
116
|
|
|
|
|
|
|
use Log::FreeSWITCH::Line qw(parse); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# Log record. |
119
|
|
|
|
|
|
|
my $data = '2014-07-01 13:37:53.973562 [DEBUG] sofia.c:4045 inbound-codec-prefs [PCMA]'; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
# Parse. |
122
|
|
|
|
|
|
|
my $data_o = parse($data); |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# Dump. |
125
|
|
|
|
|
|
|
p $data_o; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
# Output: |
128
|
|
|
|
|
|
|
# Log::FreeSWITCH::Line::Data { |
129
|
|
|
|
|
|
|
# Parents Mo::Object |
130
|
|
|
|
|
|
|
# public methods (0) |
131
|
|
|
|
|
|
|
# private methods (1) : _datetime |
132
|
|
|
|
|
|
|
# internals: { |
133
|
|
|
|
|
|
|
# date "2014-07-01", |
134
|
|
|
|
|
|
|
# file "sofia.c", |
135
|
|
|
|
|
|
|
# file_line 4045, |
136
|
|
|
|
|
|
|
# message "inbound-codec-prefs [PCMA]", |
137
|
|
|
|
|
|
|
# raw "2014-07-01 13:37:53.973562 [DEBUG] sofia.c:4045 inbound-codec-prefs [PCMA]", |
138
|
|
|
|
|
|
|
# time "13:37:53.973562", |
139
|
|
|
|
|
|
|
# type "DEBUG" |
140
|
|
|
|
|
|
|
# } |
141
|
|
|
|
|
|
|
# } |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 EXAMPLE2 |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# Pragmas. |
146
|
|
|
|
|
|
|
use strict; |
147
|
|
|
|
|
|
|
use warnings; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
# Module. |
150
|
|
|
|
|
|
|
use Log::FreeSWITCH::Line qw(serialize); |
151
|
|
|
|
|
|
|
use Log::FreeSWITCH::Line::Data; |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
# Data. |
154
|
|
|
|
|
|
|
my $record = Log::FreeSWITCH::Line::Data->new( |
155
|
|
|
|
|
|
|
'date' => '2014-07-01', |
156
|
|
|
|
|
|
|
'file' => 'sofia.c', |
157
|
|
|
|
|
|
|
'file_line' => 4045, |
158
|
|
|
|
|
|
|
'message' => 'inbound-codec-prefs [PCMA]', |
159
|
|
|
|
|
|
|
'time' => '13:37:53.973562', |
160
|
|
|
|
|
|
|
'type' => 'DEBUG', |
161
|
|
|
|
|
|
|
); |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
# Serialize and print to stdout. |
164
|
|
|
|
|
|
|
print serialize($record)."\n"; |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
# Output: |
167
|
|
|
|
|
|
|
# 2014-07-01 13:37:53.973562 [DEBUG] sofia.c:4045 inbound-codec-prefs [PCMA] |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
L<Error::Pure>, |
172
|
|
|
|
|
|
|
L<Exporter>, |
173
|
|
|
|
|
|
|
L<Log::FreeSWITCH::Line::Data>, |
174
|
|
|
|
|
|
|
L<Readonly>, |
175
|
|
|
|
|
|
|
L<Scalar::Util>. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 SEE ALSO |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=over |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=item L<Log::FreeSWITCH::Line::Data> |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Data object which represents FreeSWITCH log line. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=back |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head1 REPOSITORY |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
L<https://github.com/tupinek/Log-FreeSWITCH-Line> |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head1 AUTHOR |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Michal Å paÄek L<mailto:skim@cpan.org> |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
L<http://skim.cz> |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
© 2014-2015 Michal Å paÄek |
200
|
|
|
|
|
|
|
BSD 2-Clause License |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head1 VERSION |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
0.06 |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=cut |