line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Log4perl::ConfigByInifile; |
2
|
2
|
|
|
2
|
|
171861
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
78
|
|
3
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
55
|
|
4
|
2
|
|
|
2
|
|
1428
|
use Log::Log4perl; |
|
2
|
|
|
|
|
85558
|
|
|
2
|
|
|
|
|
16
|
|
5
|
2
|
|
|
2
|
|
2279
|
use Params::Validate qw(:all); |
|
2
|
|
|
|
|
68304
|
|
|
2
|
|
|
|
|
513
|
|
6
|
2
|
|
|
2
|
|
1274
|
use Config::IniFiles; |
|
2
|
|
|
|
|
99245
|
|
|
2
|
|
|
|
|
88
|
|
7
|
2
|
|
|
2
|
|
17
|
use Carp; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
134
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# $Revision: 10 $ |
10
|
|
|
|
|
|
|
# $Date: 2007-03-16 18:39:40 +0100 (Fri, 16 Mar 2007) $ |
11
|
|
|
|
|
|
|
# $Id: ConfigByInifile.pm 10 2007-03-16 17:39:40Z horshack $ |
12
|
|
|
|
|
|
|
# $HeadURL: http://svn.rosi13.de/svn/Log-Log4perl-ConfigByInifile/trunk/lib/Log/Log4perl/ConfigByInifile.pm $ |
13
|
|
|
|
|
|
|
# $Author: horshack $ |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
BEGIN { |
16
|
2
|
|
|
2
|
|
12
|
use base qw(Exporter); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
235
|
|
17
|
2
|
|
|
2
|
|
4
|
our $VERSION = '0.04'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# our @EXPORT = qw(); |
20
|
2
|
|
|
|
|
773
|
our @EXPORT_OK = qw(ConfigByInifile); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# our %EXPORT_TAGS = (); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 NAME |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Log::Log4perl::ConfigByInifile - Get Log::Log4perl config from an ini-File |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 VERSION |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
0.03 - more Perl Best Practices with http://perlcritic.com/perl/critic.pl |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 SYNOPSIS |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
use Log::Log4perl::ConfigByInifile; |
36
|
|
|
|
|
|
|
Log::Log4perl::ConfigByInifile->new( |
37
|
|
|
|
|
|
|
{ ini_fn => 'acme.ini', } |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
my $logger = Log::Log4perl->get_logger('main'); |
40
|
|
|
|
|
|
|
$logger->debug('Starting...'); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 DESCRIPTION |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Initialize Log::Log4perl with an ini-File. You must supply a |
46
|
|
|
|
|
|
|
section for Log4perl like this: |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
[log4perl] |
49
|
|
|
|
|
|
|
log4perl.category = INFO, Logfile, Screen |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
log4perl.appender.Logfile = Log::Log4perl::Appender::File |
52
|
|
|
|
|
|
|
log4perl.appender.Logfile.filename = your_logfile.log |
53
|
|
|
|
|
|
|
log4perl.appender.Logfile.mode = write |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
log4perl.appender.Logfile.layout = Log::Log4perl::Layout::SimpleLayout |
56
|
|
|
|
|
|
|
log4perl.appender.Screen = Log::Log4perl::Appender::Screen |
57
|
|
|
|
|
|
|
log4perl.appender.Screen.layout = Log::Log4perl::Layout::SimpleLayout |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
[myfiles] |
60
|
|
|
|
|
|
|
... |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head2 new |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
This is the only method this module has. Calling it |
68
|
|
|
|
|
|
|
initializes Log::Log4perl with the section [log4perl] |
69
|
|
|
|
|
|
|
in your inifile. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Usage: |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Log::Log4perl::ConfigByInifile->new( |
74
|
|
|
|
|
|
|
{ ini_fn => 'acme.ini', } |
75
|
|
|
|
|
|
|
); |
76
|
|
|
|
|
|
|
my $logger = Log::Log4perl->get_logger('main'); |
77
|
|
|
|
|
|
|
$logger->debug('Starting...'); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
or |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
my $ini_obj = Config::IniFiles->new( |
82
|
|
|
|
|
|
|
-file => 'acme.ini'); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Log::Log4perl::ConfigByInifile->new( |
85
|
|
|
|
|
|
|
{ ini_obj => $ini_obj, } |
86
|
|
|
|
|
|
|
); |
87
|
|
|
|
|
|
|
my $logger = Log::Log4perl->get_logger('main'); |
88
|
|
|
|
|
|
|
$logger->debug('Starting...'); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Returns: Nothing. This routine only initializes Log::Log4perl. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Argument: Either ini_file or ini_obj. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Throws: Dies in all kinds of errors with a good message (inifile |
95
|
|
|
|
|
|
|
does not exist, not even single argument given etc.) |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub new { |
100
|
6
|
|
|
6
|
1
|
6862
|
my $class = shift; |
101
|
6
|
|
|
|
|
19
|
my %defaults = ( section => 'log4perl', ); |
102
|
6
|
|
|
|
|
10
|
my $ini_section = $defaults{section}; |
103
|
|
|
|
|
|
|
|
104
|
6
|
|
|
|
|
9
|
my $args_href = shift; |
105
|
3
|
|
|
|
|
18
|
%{$args_href} = validate_with( |
106
|
|
|
|
|
|
|
params => $args_href, |
107
|
|
|
|
|
|
|
spec => { |
108
|
|
|
|
|
|
|
ini_file => { |
109
|
|
|
|
|
|
|
type => SCALAR, |
110
|
|
|
|
|
|
|
optional => 1, |
111
|
4
|
|
|
4
|
|
343
|
callbacks => { 'file_must_exist' => sub { -f $_[0] }, }, |
112
|
|
|
|
|
|
|
}, |
113
|
|
|
|
|
|
|
ini_obj => { |
114
|
|
|
|
|
|
|
type => OBJECT, |
115
|
|
|
|
|
|
|
optional => 1, |
116
|
|
|
|
|
|
|
callbacks => { |
117
|
|
|
|
|
|
|
'must_be_config_inifiles' => |
118
|
2
|
|
|
2
|
|
211
|
sub { ref $_[0] eq 'Config::IniFiles' }, |
119
|
|
|
|
|
|
|
}, |
120
|
|
|
|
|
|
|
}, |
121
|
|
|
|
|
|
|
} |
122
|
6
|
|
|
|
|
194
|
); |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# either ini_file _or_ ini_obj |
125
|
3
|
|
|
|
|
40
|
my $anz_file_obj = 0; |
126
|
3
|
50
|
|
|
|
10
|
$anz_file_obj += exists $args_href->{ini_file} ? 1 : 0; |
127
|
3
|
100
|
|
|
|
9
|
$anz_file_obj += exists $args_href->{ini_obj} ? 1 : 0; |
128
|
3
|
100
|
|
|
|
17
|
if ( $anz_file_obj != 1 ) { |
129
|
1
|
|
|
|
|
242
|
confess 'Submit either ini_file or ini_obj to new'; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
2
|
|
|
|
|
3
|
my $ini_obj; |
133
|
|
|
|
|
|
|
|
134
|
2
|
50
|
|
|
|
6
|
if ( $args_href->{ini_obj} ) { |
135
|
0
|
|
|
|
|
0
|
$ini_obj = $args_href->{ini_obj}; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
else { |
138
|
2
|
|
|
|
|
19
|
$ini_obj = Config::IniFiles->new( -file => $args_href->{ini_file} ); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
# At this point there is an ini-Object which points |
142
|
|
|
|
|
|
|
# to our ini-file |
143
|
|
|
|
|
|
|
|
144
|
2
|
100
|
|
|
|
2798
|
if ( !$ini_obj->SectionExists($ini_section) ) { |
145
|
1
|
|
|
|
|
176
|
confess "There must be a section '$ini_section' in the inifile"; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
1
|
|
|
|
|
25
|
my $log_conf; |
149
|
1
|
|
|
|
|
7
|
for my $var ( $ini_obj->Parameters($ini_section) ) { |
150
|
6
|
50
|
|
|
|
117
|
next if !defined $var; |
151
|
6
|
|
|
|
|
18
|
$log_conf .= sprintf "%s=%s\n", $var, |
152
|
|
|
|
|
|
|
$ini_obj->val( $ini_section, $var ); |
153
|
|
|
|
|
|
|
} |
154
|
1
|
|
|
|
|
21
|
Log::Log4perl::init( \$log_conf ); |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
# return something (PBP) |
157
|
1
|
|
|
|
|
4546
|
return 1; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Depends on these Perl modules: |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Log::Log4perl; |
165
|
|
|
|
|
|
|
Params::Validate; |
166
|
|
|
|
|
|
|
Config::IniFiles; |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 AUTHOR |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Richard Lippmann |
171
|
|
|
|
|
|
|
CPAN ID: HORSHACK |
172
|
|
|
|
|
|
|
horshack@lisa.franken.de |
173
|
|
|
|
|
|
|
http://lena.franken.de |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
This program is free software; you can redistribute |
178
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
The full text of the license can be found in the |
181
|
|
|
|
|
|
|
LICENSE file included with this module. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 SEE ALSO |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
perl(1). |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=cut |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
1; |