line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Log4perl::CommandLine; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
25723
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
39
|
|
4
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
74
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.07'; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
1734
|
use Log::Log4perl qw(get_logger :levels); |
|
1
|
|
|
|
|
66458
|
|
|
1
|
|
|
|
|
8
|
|
9
|
1
|
|
|
1
|
|
1538
|
use Getopt::Long; |
|
1
|
|
|
|
|
19881
|
|
|
1
|
|
|
|
|
8
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my %init; # logconfig, loginit, logfile, logcategory, noinit |
12
|
|
|
|
|
|
|
my %options; # options set on command line |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my %levelmap = |
15
|
|
|
|
|
|
|
( |
16
|
|
|
|
|
|
|
q => 'off', |
17
|
|
|
|
|
|
|
quiet => 'off', |
18
|
|
|
|
|
|
|
v => 'info', |
19
|
|
|
|
|
|
|
verbose => 'info', |
20
|
|
|
|
|
|
|
d => 'debug' |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub import |
24
|
|
|
|
|
|
|
{ |
25
|
1
|
|
|
1
|
|
14
|
my $class = shift; |
26
|
|
|
|
|
|
|
|
27
|
1
|
|
|
|
|
2
|
my $caller = caller; |
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
|
|
2
|
my @getoptlist; |
30
|
|
|
|
|
|
|
my $next; |
31
|
1
|
|
|
|
|
4
|
foreach (@_) |
32
|
|
|
|
|
|
|
{ |
33
|
0
|
0
|
|
|
|
0
|
if ($next) |
34
|
|
|
|
|
|
|
{ |
35
|
0
|
|
|
|
|
0
|
$init{$next} = $_; |
36
|
0
|
|
|
|
|
0
|
$next = undef; |
37
|
0
|
|
|
|
|
0
|
next; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
0
|
0
|
|
|
|
0
|
/^:(log(?:config|file|init|category))$/ and $next = $1; # Grab next arg |
41
|
|
|
|
|
|
|
|
42
|
0
|
0
|
|
|
|
0
|
/^(?:trace|:levels|:all)$/ and push(@getoptlist, 'trace:s@'); |
43
|
0
|
0
|
|
|
|
0
|
/^(?:debug|:levels|:all)$/ and push(@getoptlist, 'debug:s@'); |
44
|
0
|
0
|
|
|
|
0
|
/^(?:info|:levels|:all)$/ and push(@getoptlist, 'info:s@'); |
45
|
0
|
0
|
|
|
|
0
|
/^(?:warn|:levels|:all)$/ and push(@getoptlist, 'warn:s@'); |
46
|
0
|
0
|
|
|
|
0
|
/^(?:error|:levels|:all)$/ and push(@getoptlist, 'error:s@'); |
47
|
0
|
0
|
|
|
|
0
|
/^(?:fatal|:levels|:all)$/ and push(@getoptlist, 'fatal:s@'); |
48
|
0
|
0
|
|
|
|
0
|
/^(?:off|:levels|:all)$/ and push(@getoptlist, 'off:s@'); |
49
|
|
|
|
|
|
|
|
50
|
0
|
0
|
|
|
|
0
|
/^(?:quiet|:long|:all)$/ and push(@getoptlist, 'quiet:s@'); |
51
|
0
|
0
|
|
|
|
0
|
/^(?:verbose|:long|:all)$/ and push(@getoptlist, 'verbose:s@'); |
52
|
|
|
|
|
|
|
|
53
|
0
|
0
|
|
|
|
0
|
/^(?:q|:short|:all)$/ and push(@getoptlist, 'q:s@'); |
54
|
0
|
0
|
|
|
|
0
|
/^(?:v|:short|:all)$/ and push(@getoptlist, 'v:s@'); |
55
|
0
|
0
|
|
|
|
0
|
/^(?:d|:short|:all)$/ and push(@getoptlist, 'd:s@'); |
56
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
0
|
/^(?:loglevel|:logopts|:all)$/ and push(@getoptlist, 'loglevel:s@'); |
58
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
0
|
/^(?:logconfig|:logopts|:all)$/ and |
60
|
|
|
|
|
|
|
push(@getoptlist, 'logconfig=s' => \$init{logconfig}); |
61
|
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
0
|
/^(?:logfile|:logopts|:all)$/ and |
63
|
|
|
|
|
|
|
push(@getoptlist, 'logfile=s' => \$init{logfile}); |
64
|
|
|
|
|
|
|
|
65
|
1
|
|
|
1
|
|
995
|
{ no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
999
|
|
|
0
|
|
|
|
|
0
|
|
66
|
0
|
|
|
|
|
0
|
/^handlelogoptions$/ and |
67
|
0
|
0
|
|
|
|
0
|
*{"$caller\::handlelogoptions"} = *handlelogoptions; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
0
|
0
|
|
|
|
0
|
/^:noinit$/ and $init{noinit} = 1; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
1
|
|
|
|
|
11
|
my $getopt = Getopt::Long::Parser->new |
74
|
|
|
|
|
|
|
( config => [qw(pass_through no_auto_abbrev |
75
|
|
|
|
|
|
|
no_ignore_case)] ); |
76
|
|
|
|
|
|
|
|
77
|
1
|
|
|
|
|
118
|
$getopt->getoptions(\%options, @getoptlist); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# Allow: --option --option foo --option foo,bar |
80
|
1
|
|
|
|
|
96
|
while (my ($opt, $cats) = each %options) |
81
|
|
|
|
|
|
|
{ |
82
|
0
|
0
|
|
|
|
0
|
$options{$opt} = [ map { length $_ ? split(',') : '' } @$cats ]; |
|
0
|
|
|
|
|
0
|
|
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# --loglevel category=level or --loglevel level |
86
|
1
|
|
|
|
|
2
|
foreach (@{$options{loglevel}}) |
|
1
|
|
|
|
|
4
|
|
87
|
|
|
|
|
|
|
{ |
88
|
0
|
|
|
|
|
0
|
my ($category, $level) = /^([^=]*?)=?([^=]+)$/; |
89
|
0
|
|
|
|
|
0
|
push(@{$options{$level}}, $category); |
|
0
|
|
|
|
|
0
|
|
90
|
|
|
|
|
|
|
} |
91
|
1
|
|
|
|
|
21
|
delete $options{loglevel}; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
INIT |
95
|
|
|
|
|
|
|
{ |
96
|
1
|
50
|
|
1
|
|
5
|
return if $init{noinit}; |
97
|
|
|
|
|
|
|
|
98
|
1
|
50
|
33
|
|
|
8
|
if (defined $init{logconfig} and -f $init{logconfig} and -r _) |
|
|
|
33
|
|
|
|
|
99
|
|
|
|
|
|
|
{ |
100
|
0
|
|
|
|
|
0
|
Log::Log4perl->init($init{logconfig}); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
else |
103
|
|
|
|
|
|
|
{ |
104
|
1
|
50
|
33
|
|
|
17
|
if ($init{loginit} and not ref $init{loginit}) |
|
|
50
|
33
|
|
|
|
|
105
|
|
|
|
|
|
|
{ |
106
|
0
|
|
|
|
|
0
|
Log::Log4perl->init(\$init{loginit}); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
elsif ($init{loginit} and ref $init{loginit} eq 'ARRAY') |
109
|
|
|
|
|
|
|
{ |
110
|
0
|
|
|
|
|
0
|
Log::Log4perl->easy_init(@{$init{loginit}}); |
|
0
|
|
|
|
|
0
|
|
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
else |
113
|
|
|
|
|
|
|
{ |
114
|
1
|
50
|
|
|
|
5
|
my $init = ref $init{loginit} eq 'HASH' ? $init{loginit} : {}; |
115
|
|
|
|
|
|
|
|
116
|
1
|
|
33
|
|
|
11
|
$init->{level} ||= $ERROR; |
117
|
1
|
|
50
|
|
|
9
|
$init->{layout} ||= '[%-5p] %m%n'; |
118
|
|
|
|
|
|
|
|
119
|
1
|
|
|
|
|
11
|
Log::Log4perl->easy_init($init); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
1
|
|
|
|
|
2867
|
handlelogoptions(); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub handlelogoptions |
127
|
|
|
|
|
|
|
{ |
128
|
1
|
50
|
|
1
|
1
|
5
|
if ($init{logfile}) |
129
|
|
|
|
|
|
|
{ |
130
|
0
|
|
|
|
|
0
|
my $logfile = $init{logfile}; |
131
|
0
|
|
|
|
|
0
|
my $layout = '%d %c %m%n'; |
132
|
|
|
|
|
|
|
|
133
|
0
|
0
|
|
|
|
0
|
if ($logfile =~ s/\|(.*)$//) # "logfilename|logpattern" |
134
|
|
|
|
|
|
|
{ |
135
|
0
|
|
|
|
|
0
|
$layout = $1; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
0
|
my $file_appender = Log::Log4perl::Appender->new( |
139
|
|
|
|
|
|
|
"Log::Log4perl::Appender::File", |
140
|
|
|
|
|
|
|
name => 'logfile', |
141
|
|
|
|
|
|
|
filename => $logfile); |
142
|
|
|
|
|
|
|
|
143
|
0
|
|
|
|
|
0
|
$file_appender->layout(Log::Log4perl::Layout::PatternLayout->new( |
144
|
|
|
|
|
|
|
$layout)); |
145
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
0
|
get_logger('')->add_appender($file_appender); |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
1
|
|
|
|
|
113
|
while (my ($level, $vals) = each %options) |
150
|
|
|
|
|
|
|
{ |
151
|
0
|
0
|
|
|
|
|
$level = $levelmap{$level} if exists $levelmap{$level}; |
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
my $level_id = Log::Log4perl::Level::to_priority(uc $level); |
154
|
|
|
|
|
|
|
|
155
|
0
|
|
|
|
|
|
foreach my $category (@$vals) |
156
|
|
|
|
|
|
|
{ |
157
|
0
|
0
|
|
|
|
|
if ($category eq '') |
158
|
|
|
|
|
|
|
{ |
159
|
0
|
0
|
|
|
|
|
$category = defined($init{logcategory}) |
|
|
0
|
|
|
|
|
|
160
|
|
|
|
|
|
|
? $init{logcategory} |
161
|
|
|
|
|
|
|
: $level_id >= $INFO ? '' : 'main'; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
0
|
0
|
|
|
|
|
$category = '' if $category eq 'root'; |
165
|
|
|
|
|
|
|
|
166
|
0
|
|
|
|
|
|
get_logger($category)->level($level_id); |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
1; |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
__END__ |