line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Parse::Dia::SQL::Logger; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# $Id: Logger.pm,v 1.9 2011/02/16 10:23:11 aff Exp $ |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=pod |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Parse::Dia::SQL::Logger - Wrapper for Log::Log4perl |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 SYNOPSIS |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use Parse::Dia::SQL::Logger; |
14
|
|
|
|
|
|
|
my $logger = Parse::Dia::SQL::Logger::->new(loglevel => 'INFO'); |
15
|
|
|
|
|
|
|
my $log = $logger->get_logger(__PACKAGE__); |
16
|
|
|
|
|
|
|
$log->error('error'); |
17
|
|
|
|
|
|
|
$log->info('info'); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 DESCRIPTION |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
This module is a wrapper around Log::Log4perl. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=cut |
24
|
|
|
|
|
|
|
|
25
|
6
|
|
|
6
|
|
4030
|
use warnings; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
169
|
|
26
|
6
|
|
|
6
|
|
39
|
use strict; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
94
|
|
27
|
|
|
|
|
|
|
|
28
|
6
|
|
|
6
|
|
3769
|
use Log::Log4perl; |
|
6
|
|
|
|
|
223442
|
|
|
6
|
|
|
|
|
32
|
|
29
|
|
|
|
|
|
|
|
30
|
6
|
|
|
6
|
|
314
|
use constant APPENDER_THRESHOLDS_ADJUST_LOGOFF => 7; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
307
|
|
31
|
6
|
|
|
6
|
|
33
|
use constant APPENDER_THRESHOLDS_ADJUST_LOGON => -7; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
1887
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head2 new |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
The constructor. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=cut |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub new { |
40
|
0
|
|
|
0
|
1
|
|
my ( $class, %param ) = @_; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $self = { |
43
|
|
|
|
|
|
|
log => undef, |
44
|
|
|
|
|
|
|
loglevel => $param{loglevel} || undef, |
45
|
0
|
|
0
|
|
|
|
}; |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
bless( $self, $class ); |
48
|
0
|
|
|
|
|
|
$self->_init_log(); |
49
|
0
|
|
|
|
|
|
return $self; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# Initialize the logger. The commented lines are deliberately left to |
53
|
|
|
|
|
|
|
# serve as exmples. |
54
|
|
|
|
|
|
|
sub _init_log { |
55
|
0
|
|
|
0
|
|
|
my $self = shift; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# Init logging |
58
|
0
|
|
|
|
|
|
my $conf = undef; |
59
|
|
|
|
|
|
|
|
60
|
0
|
0
|
|
|
|
|
if ($self->{loglevel}) { |
61
|
0
|
|
|
|
|
|
$conf = qq( |
62
|
|
|
|
|
|
|
# Loglevel set by user |
63
|
|
|
|
|
|
|
log4perl.category.Parse::Dia::SQL = $self->{loglevel}, screen-main |
64
|
|
|
|
|
|
|
log4perl.appender.screen-main = Log::Log4perl::Appender::Screen |
65
|
|
|
|
|
|
|
log4perl.appender.screen-main.stderr = 1 |
66
|
|
|
|
|
|
|
log4perl.appender.screen-main.layout = PatternLayout |
67
|
|
|
|
|
|
|
log4perl.appender.screen-main.layout.ConversionPattern=[%p] %m%n |
68
|
|
|
|
|
|
|
); |
69
|
|
|
|
|
|
|
} else { |
70
|
|
|
|
|
|
|
# Default logging |
71
|
0
|
|
|
|
|
|
$conf = q( |
72
|
|
|
|
|
|
|
# Main logger for Parse::Dia::SQL |
73
|
|
|
|
|
|
|
log4perl.category.Parse::Dia::SQL = INFO, screen-main |
74
|
|
|
|
|
|
|
log4perl.appender.screen-main = Log::Log4perl::Appender::Screen |
75
|
|
|
|
|
|
|
log4perl.appender.screen-main.stderr = 1 |
76
|
|
|
|
|
|
|
log4perl.appender.screen-main.layout = PatternLayout |
77
|
|
|
|
|
|
|
log4perl.appender.screen-main.layout.ConversionPattern=[%p] %m%n |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# Separate logger for Output::* |
80
|
|
|
|
|
|
|
log4perl.category.Parse::Dia::SQL::Output = INFO, screen-output |
81
|
|
|
|
|
|
|
log4perl.appender.screen-output = Log::Log4perl::Appender::Screen |
82
|
|
|
|
|
|
|
log4perl.appender.screen-output.stderr = 1 |
83
|
|
|
|
|
|
|
log4perl.appender.screen-output.layout = PatternLayout |
84
|
|
|
|
|
|
|
log4perl.appender.screen-output.layout.ConversionPattern=[%p] %m%n |
85
|
|
|
|
|
|
|
log4perl.additivity.Parse::Dia::SQL::Output = 0 |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# Separate logger for Utils.pm |
88
|
|
|
|
|
|
|
log4perl.category.Parse::Dia::SQL::Utils = INFO, screen-utils |
89
|
|
|
|
|
|
|
log4perl.appender.screen-utils = Log::Log4perl::Appender::Screen |
90
|
|
|
|
|
|
|
log4perl.appender.screen-utils.stderr = 1 |
91
|
|
|
|
|
|
|
log4perl.appender.screen-utils.layout = PatternLayout |
92
|
|
|
|
|
|
|
log4perl.appender.screen-utils.layout.ConversionPattern=[%p] %m%n |
93
|
|
|
|
|
|
|
log4perl.additivity.Parse::Dia::SQL::Utils = 0 |
94
|
|
|
|
|
|
|
); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
Log::Log4perl::init( \$conf ); |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# Adjust call stack for caller class, see man Log::Log4perl |
100
|
0
|
|
|
|
|
|
$Log::Log4perl::caller_depth = 1; |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
return 1; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head2 get_logger |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Return logger singleton object. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=cut |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub get_logger { |
112
|
0
|
|
|
0
|
1
|
|
my ($self, $name) = @_; |
113
|
|
|
|
|
|
|
#return $self->{logger}; |
114
|
0
|
|
|
|
|
|
return Log::Log4perl::->get_logger($name); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head2 log_off |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Decrease log level on all appenders. |
121
|
|
|
|
|
|
|
1 |
122
|
|
|
|
|
|
|
=cut |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub log_off { |
125
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
# Make sure it works also in case this is |
128
|
|
|
|
|
|
|
# called as function before object is blessed. |
129
|
0
|
0
|
|
|
|
|
_init_log() if ( !Log::Log4perl->initialized() ); |
130
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
Log::Log4perl->appender_thresholds_adjust(APPENDER_THRESHOLDS_ADJUST_LOGOFF); |
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
return 1; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head2 log_on |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Increase log level on all appenders. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=cut |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub log_on { |
143
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# Make sure it works also in case this is |
146
|
|
|
|
|
|
|
# called as function before object is blessed. |
147
|
0
|
0
|
|
|
|
|
_init_log() if ( !Log::Log4perl->initialized() ); |
148
|
|
|
|
|
|
|
|
149
|
0
|
|
|
|
|
|
Log::Log4perl->appender_thresholds_adjust(APPENDER_THRESHOLDS_ADJUST_LOGON); |
150
|
|
|
|
|
|
|
|
151
|
0
|
|
|
|
|
|
return 1; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
1; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
__END__ |