line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Clustericious::Log::CommandLine; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
2512
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
5
|
1
|
|
|
1
|
|
515
|
use Log::Log4perl qw(get_logger :levels); |
|
1
|
|
|
|
|
33782
|
|
|
1
|
|
|
|
|
6
|
|
6
|
1
|
|
|
1
|
|
682
|
use Getopt::Long; |
|
1
|
|
|
|
|
8367
|
|
|
1
|
|
|
|
|
5
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# ABSTRACT: Simple Command Line Interface for Log4perl |
9
|
|
|
|
|
|
|
our $VERSION = '1.27'; # VERSION |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my %init; # logconfig, loginit, logfile, logcategory, noinit |
13
|
|
|
|
|
|
|
my %options; # options set on command line |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my %levelmap = |
16
|
|
|
|
|
|
|
( |
17
|
|
|
|
|
|
|
q => 'off', |
18
|
|
|
|
|
|
|
quiet => 'off', |
19
|
|
|
|
|
|
|
v => 'info', |
20
|
|
|
|
|
|
|
verbose => 'info', |
21
|
|
|
|
|
|
|
d => 'debug' |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub import |
25
|
|
|
|
|
|
|
{ |
26
|
0
|
|
|
0
|
|
|
my $class = shift; |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
my $caller = caller; |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
my @getoptlist; |
31
|
|
|
|
|
|
|
my $next; |
32
|
0
|
|
|
|
|
|
foreach (@_) |
33
|
|
|
|
|
|
|
{ |
34
|
0
|
0
|
|
|
|
|
if ($next) |
35
|
|
|
|
|
|
|
{ |
36
|
0
|
|
|
|
|
|
$init{$next} = $_; |
37
|
0
|
|
|
|
|
|
$next = undef; |
38
|
0
|
|
|
|
|
|
next; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
0
|
0
|
|
|
|
|
/^:(log(?:config|file|init|category))$/ and $next = $1; # Grab next arg |
42
|
|
|
|
|
|
|
|
43
|
0
|
0
|
|
|
|
|
/^(?:trace|:levels|:all)$/ and push(@getoptlist, 'trace:s@'); |
44
|
0
|
0
|
|
|
|
|
/^(?:debug|:levels|:all)$/ and push(@getoptlist, 'debug:s@'); |
45
|
0
|
0
|
|
|
|
|
/^(?:info|:levels|:all)$/ and push(@getoptlist, 'info:s@'); |
46
|
0
|
0
|
|
|
|
|
/^(?:warn|:levels|:all)$/ and push(@getoptlist, 'warn:s@'); |
47
|
0
|
0
|
|
|
|
|
/^(?:error|:levels|:all)$/ and push(@getoptlist, 'error:s@'); |
48
|
0
|
0
|
|
|
|
|
/^(?:fatal|:levels|:all)$/ and push(@getoptlist, 'fatal:s@'); |
49
|
0
|
0
|
|
|
|
|
/^(?:off|:levels|:all)$/ and push(@getoptlist, 'off:s@'); |
50
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
|
/^(?:quiet|:long|:all)$/ and push(@getoptlist, 'quiet:s@'); |
52
|
0
|
0
|
|
|
|
|
/^(?:verbose|:long|:all)$/ and push(@getoptlist, 'verbose:s@'); |
53
|
|
|
|
|
|
|
|
54
|
0
|
0
|
|
|
|
|
/^(?:q|:short|:all)$/ and push(@getoptlist, 'q:s@'); |
55
|
0
|
0
|
|
|
|
|
/^(?:v|:short|:all)$/ and push(@getoptlist, 'v:s@'); |
56
|
0
|
0
|
|
|
|
|
/^(?:d|:short|:all)$/ and push(@getoptlist, 'd:s@'); |
57
|
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
|
/^(?:loglevel|:logopts|:all)$/ and push(@getoptlist, 'loglevel:s@'); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
/^(?:logconfig|:logopts|:all)$/ and |
61
|
0
|
0
|
|
|
|
|
push(@getoptlist, 'logconfig=s' => \$init{logconfig}); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
/^(?:logfile|:logopts|:all)$/ and |
64
|
0
|
0
|
|
|
|
|
push(@getoptlist, 'logfile=s' => \$init{logfile}); |
65
|
|
|
|
|
|
|
|
66
|
1
|
|
|
1
|
|
637
|
{ no strict 'refs'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
268
|
|
|
0
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
/^handlelogoptions$/ and |
68
|
0
|
0
|
|
|
|
|
*{"$caller\::handlelogoptions"} = *handlelogoptions; |
|
0
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
0
|
0
|
|
|
|
|
/^:noinit$/ and $init{noinit} = 1; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
my $getopt = Getopt::Long::Parser->new |
75
|
|
|
|
|
|
|
( config => [qw(pass_through no_auto_abbrev |
76
|
|
|
|
|
|
|
no_ignore_case)] ); |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
$getopt->getoptions(\%options, @getoptlist); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# Allow: --option --option foo --option foo,bar |
81
|
0
|
|
|
|
|
|
while (my ($opt, $cats) = each %options) |
82
|
|
|
|
|
|
|
{ |
83
|
0
|
0
|
|
|
|
|
$options{$opt} = [ map { length $_ ? split(',') : '' } @$cats ]; |
|
0
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# --loglevel category=level or --loglevel level |
87
|
0
|
|
|
|
|
|
foreach (@{$options{loglevel}}) |
|
0
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
{ |
89
|
0
|
|
|
|
|
|
my ($category, $level) = /^([^=]*?)=?([^=]+)$/; |
90
|
0
|
|
|
|
|
|
push(@{$options{$level}}, $category); |
|
0
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
} |
92
|
0
|
|
|
|
|
|
delete $options{loglevel}; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
1
|
|
|
1
|
|
7
|
no warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
51
|
|
96
|
|
|
|
|
|
|
INIT |
97
|
|
|
|
|
|
|
{ |
98
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
155
|
|
99
|
|
|
|
|
|
|
return if $init{noinit}; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
if (defined $init{logconfig} and -f $init{logconfig} and -r _) |
102
|
|
|
|
|
|
|
{ |
103
|
|
|
|
|
|
|
Log::Log4perl->init($init{logconfig}); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
else |
106
|
|
|
|
|
|
|
{ |
107
|
|
|
|
|
|
|
if ($init{loginit} and not ref $init{loginit}) |
108
|
|
|
|
|
|
|
{ |
109
|
|
|
|
|
|
|
Log::Log4perl->init(\$init{loginit}); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
elsif ($init{loginit} and ref $init{loginit} eq 'ARRAY') |
112
|
|
|
|
|
|
|
{ |
113
|
|
|
|
|
|
|
Log::Log4perl->easy_init(@{$init{loginit}}); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
else |
116
|
|
|
|
|
|
|
{ |
117
|
|
|
|
|
|
|
my $init = ref $init{loginit} eq 'HASH' ? $init{loginit} : {}; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
$init->{level} ||= $ERROR; |
120
|
|
|
|
|
|
|
$init->{layout} ||= '[%-5p] %m%n'; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Log::Log4perl->easy_init($init); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
handlelogoptions(); |
127
|
|
|
|
|
|
|
} |
128
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
226
|
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub handlelogoptions |
132
|
|
|
|
|
|
|
{ |
133
|
0
|
0
|
|
0
|
1
|
|
if ($init{logfile}) |
134
|
|
|
|
|
|
|
{ |
135
|
0
|
|
|
|
|
|
my $logfile = $init{logfile}; |
136
|
0
|
|
|
|
|
|
my $layout = '%d %c %m%n'; |
137
|
|
|
|
|
|
|
|
138
|
0
|
0
|
|
|
|
|
if ($logfile =~ s/\|(.*)$//) # "logfilename|logpattern" |
139
|
|
|
|
|
|
|
{ |
140
|
0
|
|
|
|
|
|
$layout = $1; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
0
|
|
|
|
|
|
my $file_appender = Log::Log4perl::Appender->new( |
144
|
|
|
|
|
|
|
"Log::Log4perl::Appender::File", |
145
|
|
|
|
|
|
|
name => 'logfile', |
146
|
|
|
|
|
|
|
filename => $logfile); |
147
|
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
|
$file_appender->layout(Log::Log4perl::Layout::PatternLayout->new( |
149
|
|
|
|
|
|
|
$layout)); |
150
|
|
|
|
|
|
|
|
151
|
0
|
|
|
|
|
|
get_logger('')->add_appender($file_appender); |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
0
|
|
|
|
|
|
while (my ($level, $vals) = each %options) |
155
|
|
|
|
|
|
|
{ |
156
|
0
|
0
|
|
|
|
|
$level = $levelmap{$level} if exists $levelmap{$level}; |
157
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
|
my $level_id = Log::Log4perl::Level::to_priority(uc $level); |
159
|
|
|
|
|
|
|
|
160
|
0
|
|
|
|
|
|
foreach my $category (@$vals) |
161
|
|
|
|
|
|
|
{ |
162
|
0
|
0
|
|
|
|
|
if ($category eq '') |
163
|
|
|
|
|
|
|
{ |
164
|
|
|
|
|
|
|
$category = defined($init{logcategory}) |
165
|
|
|
|
|
|
|
? $init{logcategory} |
166
|
0
|
0
|
|
|
|
|
: $level_id >= $INFO ? '' : 'main'; |
|
|
0
|
|
|
|
|
|
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
0
|
0
|
|
|
|
|
$category = '' if $category eq 'root'; |
170
|
|
|
|
|
|
|
|
171
|
0
|
|
|
|
|
|
get_logger($category)->level($level_id); |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
1; |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
__END__ |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=pod |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=encoding UTF-8 |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 NAME |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Clustericious::Log::CommandLine - Simple Command Line Interface for Log4perl |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head1 VERSION |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
version 1.27 |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head1 SYNOPSIS |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
use Clustericious::Log::CommandLine; |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head1 DESCRIPTION |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
This is a fork of L<Log::Log4perl::CommandLine> used internally by |
199
|
|
|
|
|
|
|
L<Clustericious>. This module is used for legacy purposes and may |
200
|
|
|
|
|
|
|
be removed in the future, so do not use or depend on it. |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head1 FUNCTIONS |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=head2 handlelogoptions |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=head1 AUTHOR |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
Original author: Brian Duggan |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
Current maintainer: Graham Ollis E<lt>plicease@cpan.orgE<gt> |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
Contributors: |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
Curt Tilmes |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
Yanick Champoux |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
This software is copyright (c) 2013 by NASA GSFC. |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
223
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=cut |