| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package DBIx::PgLink::Logger; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
12
|
use strict; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
74
|
|
|
4
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
47
|
|
|
5
|
2
|
|
|
2
|
|
11
|
use Carp; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
152
|
|
|
6
|
2
|
|
|
2
|
|
10
|
use Exporter; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
1574
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @EXPORT = qw/trace_level trace_msg/; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $trace_level = 0; |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub trace_level(;$) { |
|
15
|
0
|
0
|
|
0
|
1
|
|
$trace_level = shift if @_; |
|
16
|
0
|
|
|
|
|
|
return $trace_level; |
|
17
|
|
|
|
|
|
|
} |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my %ELOG_SEVERITY; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $PLPERL = do { |
|
22
|
|
|
|
|
|
|
eval { main::DEBUG() }; |
|
23
|
|
|
|
|
|
|
$@ ? 0 : 1; |
|
24
|
|
|
|
|
|
|
}; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub trace_msg($$) { |
|
27
|
0
|
0
|
|
0
|
1
|
|
my ($severity, $message) = |
|
28
|
|
|
|
|
|
|
(@_ == 1) ? ('L', $_[0]) : @_; |
|
29
|
|
|
|
|
|
|
|
|
30
|
0
|
0
|
|
|
|
|
if ($PLPERL) { |
|
31
|
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
$message = format_log_message($severity, $message, 1); |
|
33
|
|
|
|
|
|
|
|
|
34
|
0
|
0
|
|
|
|
|
unless (%ELOG_SEVERITY) { |
|
35
|
0
|
|
|
|
|
|
%ELOG_SEVERITY = ( |
|
36
|
|
|
|
|
|
|
'D' => main::DEBUG(), |
|
37
|
|
|
|
|
|
|
'L' => main::LOG(), # (default) |
|
38
|
|
|
|
|
|
|
'T' => main::INFO(), # TRACE (alias) |
|
39
|
|
|
|
|
|
|
'I' => main::INFO(), |
|
40
|
|
|
|
|
|
|
'N' => main::NOTICE(), |
|
41
|
|
|
|
|
|
|
'W' => main::WARNING(), |
|
42
|
|
|
|
|
|
|
'E' => main::ERROR(), # or EXCEPTION |
|
43
|
|
|
|
|
|
|
'F' => main::ERROR(), # FATAL (alias) |
|
44
|
|
|
|
|
|
|
); |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
main::elog( |
|
47
|
0
|
|
0
|
|
|
|
$ELOG_SEVERITY{substr($severity,0,1)} || main::LOG(), |
|
48
|
|
|
|
|
|
|
$message |
|
49
|
|
|
|
|
|
|
); |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
} else { |
|
52
|
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
$message = format_log_message($severity, $message, 0); |
|
54
|
|
|
|
|
|
|
|
|
55
|
0
|
0
|
|
|
|
|
if ($severity =~ /^E/) { |
|
56
|
0
|
|
|
|
|
|
confess $message, "\n"; |
|
57
|
|
|
|
|
|
|
} else { |
|
58
|
0
|
|
|
|
|
|
warn $message, "\n"; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub format_log_message { |
|
66
|
0
|
|
|
0
|
0
|
|
my ($severity, $message, $plperl) = @_; |
|
67
|
0
|
0
|
|
|
|
|
$message = "$severity: $message" unless $plperl; |
|
68
|
0
|
0
|
0
|
|
|
|
if ($severity =~ /ERROR|FATAL|PANIC/) { |
|
|
|
0
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# full stack trace |
|
70
|
0
|
|
|
|
|
|
$message .= "\n" . Carp::longmess; |
|
71
|
|
|
|
|
|
|
} elsif ( |
|
72
|
|
|
|
|
|
|
$severity ne 'TRACE' # skip DBI tracing |
|
73
|
|
|
|
|
|
|
&& trace_level > 2 # developer levels |
|
74
|
|
|
|
|
|
|
) { |
|
75
|
|
|
|
|
|
|
# caller (skip meta class methods) |
|
76
|
0
|
|
|
|
|
|
my $i = 2; |
|
77
|
0
|
|
|
|
|
|
while ( my ($package, $filename, $line, $subroutine) = caller($i++)) { |
|
78
|
0
|
0
|
|
|
|
|
next if $subroutine =~ /^(Class::MOP)|(Moose)|(^main::__ANON__)/; |
|
79
|
0
|
|
|
|
|
|
$message .= " ($subroutine, at $filename line $line)"; |
|
80
|
0
|
|
|
|
|
|
last; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
} |
|
83
|
0
|
|
|
|
|
|
return $message; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
__END__ |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=pod |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 NAME |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
DBIx::PgLink::Logger - conditionally redirect message to PostgreSQL log |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 SUBROUTINES |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=over |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=item C<trace_level> |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
trace_level($level); |
|
103
|
|
|
|
|
|
|
$level = trace_level(); |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Set or get tracing level. Exported by default. |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=over |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item * |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
0 - no trace |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=item * |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
1 - general messages for user |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=item * |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
2 - detailed messages for user |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item * |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
3,4,5 - verbose trace for developer |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=back |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item C<trace_msg> |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
trace_msg($severity, $message); |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Write message to log. Exported by default. |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Severity is PostgreSQL message level for C<elog>. Possible values: |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=over |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=item * |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
'DEBUG' |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item * |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
'LOG' |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item * |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
'INFO' |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=item * |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
'NOTICE' |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=item * |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
'WARNING' |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=item * |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
'ERROR'. Raise an exception, like C<die>. |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=back |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=back |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=cut |