line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Paranoid::Log::Buffer -- Log buffer support for paranoid programs |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# $Id: lib/Paranoid/Log/Buffer.pm, 2.08 2020/12/31 12:10:06 acorliss Exp $ |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# This software is free software. Similar to Perl, you can redistribute it |
6
|
|
|
|
|
|
|
# and/or modify it under the terms of either: |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# a) the GNU General Public License |
9
|
|
|
|
|
|
|
# as published by the |
10
|
|
|
|
|
|
|
# Free Software Foundation ; either version 1 |
11
|
|
|
|
|
|
|
# , or any later version |
12
|
|
|
|
|
|
|
# , or |
13
|
|
|
|
|
|
|
# b) the Artistic License 2.0 |
14
|
|
|
|
|
|
|
# , |
15
|
|
|
|
|
|
|
# |
16
|
|
|
|
|
|
|
# subject to the following additional term: No trademark rights to |
17
|
|
|
|
|
|
|
# "Paranoid" have been or are conveyed under any of the above licenses. |
18
|
|
|
|
|
|
|
# However, "Paranoid" may be used fairly to describe this unmodified |
19
|
|
|
|
|
|
|
# software, in good faith, but not as a trademark. |
20
|
|
|
|
|
|
|
# |
21
|
|
|
|
|
|
|
# (c) 2005 - 2020, Arthur Corliss (corliss@digitalmages.com) |
22
|
|
|
|
|
|
|
# (tm) 2008 - 2020, Paranoid Inc. (www.paranoid.com) |
23
|
|
|
|
|
|
|
# |
24
|
|
|
|
|
|
|
##################################################################### |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
##################################################################### |
27
|
|
|
|
|
|
|
# |
28
|
|
|
|
|
|
|
# Environment definitions |
29
|
|
|
|
|
|
|
# |
30
|
|
|
|
|
|
|
##################################################################### |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
package Paranoid::Log::Buffer; |
33
|
|
|
|
|
|
|
|
34
|
3
|
|
|
3
|
|
520
|
use 5.008; |
|
3
|
|
|
|
|
10
|
|
35
|
|
|
|
|
|
|
|
36
|
3
|
|
|
3
|
|
16
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
61
|
|
37
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
84
|
|
38
|
3
|
|
|
3
|
|
14
|
use vars qw($VERSION); |
|
3
|
|
|
|
|
22
|
|
|
3
|
|
|
|
|
142
|
|
39
|
3
|
|
|
3
|
|
17
|
use Paranoid::Debug qw(:all); |
|
3
|
|
|
|
|
16
|
|
|
3
|
|
|
|
|
768
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
($VERSION) = ( q$Revision: 2.08 $ =~ /(\d+(?:\.\d+)+)/sm ); |
42
|
|
|
|
|
|
|
|
43
|
3
|
|
|
3
|
|
33
|
use constant DEFAULT_BUFFSIZE => 20; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
1359
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
##################################################################### |
46
|
|
|
|
|
|
|
# |
47
|
|
|
|
|
|
|
# Module code follows |
48
|
|
|
|
|
|
|
# |
49
|
|
|
|
|
|
|
##################################################################### |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
{ |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Buffers |
54
|
|
|
|
|
|
|
my %buffers = (); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub addLogger { |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# Purpose: Creates the named buffer |
59
|
|
|
|
|
|
|
# Returns: Boolean |
60
|
|
|
|
|
|
|
# Usage: $rv = addLogger(%rec); |
61
|
|
|
|
|
|
|
|
62
|
4
|
|
|
4
|
1
|
15
|
my %rec = @_; |
63
|
|
|
|
|
|
|
|
64
|
4
|
|
|
|
|
12
|
$buffers{ $rec{name} } = []; |
65
|
|
|
|
|
|
|
|
66
|
4
|
|
|
|
|
12
|
return 1; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub delLogger { |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# Purpose: Deletes the named buffer |
72
|
|
|
|
|
|
|
# Returns: True (1) |
73
|
|
|
|
|
|
|
# Usage: $rv = _delBuffer($name); |
74
|
|
|
|
|
|
|
|
75
|
1
|
|
|
1
|
1
|
2
|
my $name = shift; |
76
|
|
|
|
|
|
|
|
77
|
1
|
50
|
|
|
|
4
|
delete $buffers{$name} if exists $buffers{$name}; |
78
|
|
|
|
|
|
|
|
79
|
1
|
|
|
|
|
3
|
return 1; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub init { |
83
|
2
|
|
|
2
|
1
|
113
|
return 1; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub logMsg { |
87
|
134
|
|
|
134
|
1
|
438
|
my %record = @_; |
88
|
134
|
|
|
|
|
208
|
my ( $rv, $size, $buffer ); |
89
|
|
|
|
|
|
|
|
90
|
134
|
|
|
|
|
401
|
pdebug( 'entering w/%s', PDLEVEL1, %record ); |
91
|
134
|
|
|
|
|
335
|
pIn(); |
92
|
|
|
|
|
|
|
|
93
|
134
|
50
|
|
|
|
295
|
if ( exists $buffers{ $record{name} } ) { |
94
|
|
|
|
|
|
|
$size = |
95
|
|
|
|
|
|
|
exists $record{options}{size} |
96
|
|
|
|
|
|
|
? $record{options}{size} |
97
|
134
|
100
|
|
|
|
261
|
: DEFAULT_BUFFSIZE; |
98
|
134
|
|
|
|
|
188
|
$buffer = $buffers{ $record{name} }; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# Add the message |
101
|
134
|
|
|
|
|
324
|
push @$buffer, [ @record{qw(msgtime message)} ]; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# Trim if needed |
104
|
134
|
|
|
|
|
294
|
while ( scalar @$buffer > $size ) { |
105
|
52
|
|
|
|
|
116
|
shift @$buffer; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
134
|
|
|
|
|
194
|
$rv = 1; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
134
|
|
|
|
|
301
|
pOut(); |
112
|
134
|
|
|
|
|
286
|
pdebug( 'leaving w/rv: %s', PDLEVEL1, $rv ); |
113
|
|
|
|
|
|
|
|
114
|
134
|
|
|
|
|
503
|
return $rv; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub dumpBuffer { |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# Purpose: Returns the contents of the named buffer |
120
|
|
|
|
|
|
|
# Returns: Array |
121
|
|
|
|
|
|
|
# Usage: @events = dump($name); |
122
|
|
|
|
|
|
|
|
123
|
12
|
|
|
12
|
1
|
57
|
my $name = shift; |
124
|
12
|
|
|
|
|
20
|
my @rv; |
125
|
|
|
|
|
|
|
|
126
|
12
|
50
|
|
|
|
32
|
@rv = @{ $buffers{$name} } if exists $buffers{$name}; |
|
12
|
|
|
|
|
31
|
|
127
|
|
|
|
|
|
|
|
128
|
12
|
|
|
|
|
59
|
return @rv; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
1; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
__END__ |