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.10 2022/03/08 00:01:04 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
|
|
733
|
use 5.008; |
|
3
|
|
|
|
|
9
|
|
35
|
|
|
|
|
|
|
|
36
|
3
|
|
|
3
|
|
14
|
use strict; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
50
|
|
37
|
3
|
|
|
3
|
|
12
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
66
|
|
38
|
3
|
|
|
3
|
|
12
|
use vars qw($VERSION); |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
145
|
|
39
|
3
|
|
|
3
|
|
16
|
use Paranoid::Debug qw(:all); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
653
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
($VERSION) = ( q$Revision: 2.10 $ =~ /(\d+(?:\.\d+)+)/sm ); |
42
|
|
|
|
|
|
|
|
43
|
3
|
|
|
3
|
|
21
|
use constant DEFAULT_BUFFSIZE => 20; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
1113
|
|
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
|
13
|
my %rec = @_; |
63
|
|
|
|
|
|
|
|
64
|
4
|
|
|
|
|
8
|
$buffers{ $rec{name} } = []; |
65
|
|
|
|
|
|
|
|
66
|
4
|
|
|
|
|
9
|
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
|
|
|
|
2
|
delete $buffers{$name} if exists $buffers{$name}; |
78
|
|
|
|
|
|
|
|
79
|
1
|
|
|
|
|
3
|
return 1; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub init { |
83
|
2
|
|
|
2
|
1
|
136
|
return 1; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub logMsg { |
87
|
134
|
|
|
134
|
1
|
359
|
my %record = @_; |
88
|
134
|
|
|
|
|
175
|
my ( $rv, $size, $buffer ); |
89
|
|
|
|
|
|
|
|
90
|
134
|
|
|
|
|
246
|
subPreamble( PDLEVEL1, '%' ); |
91
|
|
|
|
|
|
|
|
92
|
134
|
50
|
|
|
|
262
|
if ( exists $buffers{ $record{name} } ) { |
93
|
|
|
|
|
|
|
$size = |
94
|
|
|
|
|
|
|
exists $record{options}{size} |
95
|
|
|
|
|
|
|
? $record{options}{size} |
96
|
134
|
100
|
|
|
|
207
|
: DEFAULT_BUFFSIZE; |
97
|
134
|
|
|
|
|
176
|
$buffer = $buffers{ $record{name} }; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# Add the message |
100
|
134
|
|
|
|
|
246
|
push @$buffer, [ @record{qw(msgtime message)} ]; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# Trim if needed |
103
|
134
|
|
|
|
|
218
|
while ( scalar @$buffer > $size ) { |
104
|
52
|
|
|
|
|
100
|
shift @$buffer; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
134
|
|
|
|
|
155
|
$rv = 1; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
134
|
|
|
|
|
286
|
subPostamble( PDLEVEL1, '$', $rv ); |
111
|
|
|
|
|
|
|
|
112
|
134
|
|
|
|
|
368
|
return $rv; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub dumpBuffer { |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# Purpose: Returns the contents of the named buffer |
118
|
|
|
|
|
|
|
# Returns: Array |
119
|
|
|
|
|
|
|
# Usage: @events = dump($name); |
120
|
|
|
|
|
|
|
|
121
|
12
|
|
|
12
|
1
|
40
|
my $name = shift; |
122
|
12
|
|
|
|
|
14
|
my @rv; |
123
|
|
|
|
|
|
|
|
124
|
12
|
50
|
|
|
|
26
|
@rv = @{ $buffers{$name} } if exists $buffers{$name}; |
|
12
|
|
|
|
|
41
|
|
125
|
|
|
|
|
|
|
|
126
|
12
|
|
|
|
|
51
|
return @rv; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
__END__ |