| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Log4Perl::ImportHandle; # Imports a Log4Perl handle with category |
|
2
|
|
|
|
|
|
|
$Log4Perl::ImportHandle::VERSION = '0.031'; |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# This class imports an easy to use Log4Perl handle to the current class. Instead of |
|
5
|
|
|
|
|
|
|
# the not recommended way to use direct functions like DEBUG(), here you can define |
|
6
|
|
|
|
|
|
|
# a category. |
|
7
|
|
|
|
|
|
|
# |
|
8
|
|
|
|
|
|
|
# SYNOPSIS |
|
9
|
|
|
|
|
|
|
# ======== |
|
10
|
|
|
|
|
|
|
# |
|
11
|
|
|
|
|
|
|
# # Imports function LOG() to access category 'area1' |
|
12
|
|
|
|
|
|
|
# use Log4Perl::ImportHandle LOG => 'area1' |
|
13
|
|
|
|
|
|
|
# |
|
14
|
|
|
|
|
|
|
# # Imports also function LOG2() to access category 'area2' |
|
15
|
|
|
|
|
|
|
# Log4Perl::ImportHandle LOG => 'area1',LOG2 => 'area2 |
|
16
|
|
|
|
|
|
|
# |
|
17
|
|
|
|
|
|
|
# # Imports function logger() to access category '' (default) |
|
18
|
|
|
|
|
|
|
# use Log4Perl::ImportHandle logger |
|
19
|
|
|
|
|
|
|
# |
|
20
|
|
|
|
|
|
|
# # Imports function LOG() to access category '' (default) |
|
21
|
|
|
|
|
|
|
# # LOG is the default function name. |
|
22
|
|
|
|
|
|
|
# use Log4Perl::ImportHandle |
|
23
|
|
|
|
|
|
|
# |
|
24
|
|
|
|
|
|
|
# LOG->debug('hello'); |
|
25
|
|
|
|
|
|
|
# |
|
26
|
|
|
|
|
|
|
# WHY |
|
27
|
|
|
|
|
|
|
# === |
|
28
|
|
|
|
|
|
|
# Please have a look at the normal way to handle with Log4Perl: |
|
29
|
|
|
|
|
|
|
# |
|
30
|
|
|
|
|
|
|
# my $log = Log::Log4perl->get_logger('area1'); |
|
31
|
|
|
|
|
|
|
# $log->debug('hello'); |
|
32
|
|
|
|
|
|
|
# |
|
33
|
|
|
|
|
|
|
# For classes with some methods, that is not very nice to read and maintain. You will |
|
34
|
|
|
|
|
|
|
# also need that lines in every method again. |
|
35
|
|
|
|
|
|
|
# |
|
36
|
|
|
|
|
|
|
# With Log4Perl::ImportHandle it gets a bit smoother: |
|
37
|
|
|
|
|
|
|
# |
|
38
|
|
|
|
|
|
|
# use Log4Perl::ImportHandle |
|
39
|
|
|
|
|
|
|
# |
|
40
|
|
|
|
|
|
|
# LOG->debug('hello'); |
|
41
|
|
|
|
|
|
|
# |
|
42
|
|
|
|
|
|
|
# Once you called it in the header via 'use', you can easily access it with the default function 'LOG' |
|
43
|
|
|
|
|
|
|
# or any other you defined. |
|
44
|
|
|
|
|
|
|
# |
|
45
|
|
|
|
|
|
|
# HOWTO |
|
46
|
|
|
|
|
|
|
# ===== |
|
47
|
|
|
|
|
|
|
# As the SYNOPSIS examples above, just 'use' the class and add maybe some parameters. |
|
48
|
|
|
|
|
|
|
# |
|
49
|
|
|
|
|
|
|
# What is called a handler here, is just a function, that returns the same as get_logger() from Log4Perl. |
|
50
|
|
|
|
|
|
|
# |
|
51
|
|
|
|
|
|
|
# no parameters - Sets the default handle 'LOG'. |
|
52
|
|
|
|
|
|
|
# |
|
53
|
|
|
|
|
|
|
# one parameter - Sets the handle (function) name. |
|
54
|
|
|
|
|
|
|
# |
|
55
|
|
|
|
|
|
|
# two parameters or pairs - first is the handlename and the second the category name. You can define many pairs. |
|
56
|
|
|
|
|
|
|
# |
|
57
|
|
|
|
|
|
|
# |
|
58
|
|
|
|
|
|
|
# LICENSE |
|
59
|
|
|
|
|
|
|
# ======= |
|
60
|
|
|
|
|
|
|
# You can redistribute it and/or modify it under the conditions of LGPL. |
|
61
|
|
|
|
|
|
|
# |
|
62
|
|
|
|
|
|
|
# AUTHOR |
|
63
|
|
|
|
|
|
|
# ====== |
|
64
|
|
|
|
|
|
|
# Andreas Hernitscheck ahernit(AT)cpan.org |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
|
69
|
2
|
|
|
2
|
|
56003
|
use strict; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
69
|
|
|
70
|
2
|
|
|
2
|
|
835
|
use Log::Log4perl; |
|
|
2
|
|
|
|
|
39692
|
|
|
|
2
|
|
|
|
|
10
|
|
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# Don't use that method! It is not a method but used by perl when |
|
75
|
|
|
|
|
|
|
# this class is included to export a function in current namespace. |
|
76
|
|
|
|
|
|
|
sub import { |
|
77
|
4
|
|
|
4
|
|
742
|
my $pkg = shift; |
|
78
|
|
|
|
|
|
|
|
|
79
|
4
|
|
|
|
|
7
|
my @param = @_; |
|
80
|
|
|
|
|
|
|
|
|
81
|
4
|
|
|
|
|
4
|
my %pair; |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
|
84
|
4
|
100
|
|
|
|
13
|
if (scalar(@param) == 0){ ## no parameters |
|
|
|
100
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
|
86
|
2
|
|
|
|
|
4
|
$pair{'LOG'} = ''; |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
}elsif (scalar(@param) == 1){ ## one parameter |
|
89
|
|
|
|
|
|
|
|
|
90
|
1
|
|
|
|
|
3
|
$pair{ $param[0] } = ''; |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
}else{ ## any parameter |
|
93
|
1
|
|
|
|
|
2
|
%pair = @param; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
|
97
|
4
|
|
|
|
|
6
|
my $caller = caller; |
|
98
|
|
|
|
|
|
|
|
|
99
|
4
|
|
|
|
|
847
|
require Exporter::AutoClean; |
|
100
|
|
|
|
|
|
|
|
|
101
|
4
|
|
|
|
|
19358
|
foreach my $exportfunc (keys %pair){ |
|
102
|
|
|
|
|
|
|
|
|
103
|
5
|
|
|
|
|
34
|
my $cat = $pair{$exportfunc}; |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
my %exports = ( |
|
106
|
4
|
|
|
4
|
|
10168
|
"$exportfunc" => sub { return Log::Log4perl->get_logger( $cat ); }, |
|
107
|
5
|
|
|
|
|
22
|
); |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# installs the function $exportfunc in the calling class |
|
110
|
5
|
|
|
|
|
21
|
Exporter::AutoClean->export( $caller, %exports ); |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
1; |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
#################### pod generated by Pod::Autopod - keep this line to make pod updates possible #################### |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 NAME |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Log4Perl::ImportHandle - Imports a Log4Perl handle with category |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# Imports function LOG() to access category 'area1' |
|
133
|
|
|
|
|
|
|
use Log4Perl::ImportHandle LOG => 'area1' |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
# Imports also function LOG2() to access category 'area2' |
|
136
|
|
|
|
|
|
|
Log4Perl::ImportHandle LOG => 'area1',LOG2 => 'area2 |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
# Imports function logger() to access category '' (default) |
|
139
|
|
|
|
|
|
|
use Log4Perl::ImportHandle logger |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
# Imports function LOG() to access category '' (default) |
|
142
|
|
|
|
|
|
|
# LOG is the default function name. |
|
143
|
|
|
|
|
|
|
use Log4Perl::ImportHandle |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
LOG->debug('hello'); |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
This class imports an easy to use Log4Perl handle to the current class. Instead of |
|
152
|
|
|
|
|
|
|
the not recommended way to use direct functions like DEBUG(), here you can define |
|
153
|
|
|
|
|
|
|
a category. |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 REQUIRES |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
L |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 HOWTO |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
As the SYNOPSIS examples above, just 'use' the class and add maybe some parameters. |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
What is called a handler here, is just a function, that returns the same as get_logger() from Log4Perl. |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
no parameters - Sets the default handle 'LOG'. |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
one parameter - Sets the handle (function) name. |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
two parameters or pairs - first is the handlename and the second the category name. You can define many pairs. |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head1 WHY |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Please have a look at the normal way to handle with Log4Perl: |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
my $log = Log::Log4perl->get_logger('area1'); |
|
181
|
|
|
|
|
|
|
$log->debug('hello'); |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
For classes with some methods, that is not very nice to read and maintain. You will |
|
184
|
|
|
|
|
|
|
also need that lines in every method again. |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
With Log4Perl::ImportHandle it gets a bit smoother: |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
use Log4Perl::ImportHandle |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
LOG->debug('hello'); |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
Once you called it in the header via 'use', you can easily access it with the default function 'LOG' |
|
193
|
|
|
|
|
|
|
or any other you defined. |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head1 AUTHOR |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Andreas Hernitscheck ahernit(AT)cpan.org |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head1 LICENSE |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
You can redistribute it and/or modify it under the conditions of LGPL. |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=cut |
|
209
|
|
|
|
|
|
|
|