line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id$ |
2
|
|
|
|
|
|
|
require 5.008; |
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
94307
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
61
|
|
5
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
51
|
|
6
|
2
|
|
|
2
|
|
10
|
use Carp qw(croak cluck); |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
127
|
|
7
|
2
|
|
|
2
|
|
2058
|
use Log::Any; |
|
2
|
|
|
|
|
2702
|
|
|
2
|
|
|
|
|
9
|
|
8
|
2
|
|
|
2
|
|
1163
|
use Data::Dumper; |
|
2
|
|
|
|
|
12714
|
|
|
2
|
|
|
|
|
151
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
package DBIx::LogAny; |
11
|
2
|
|
|
2
|
|
1203
|
use DBIx::LogAny::Constants qw (:masks $LogMask); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
396
|
|
12
|
2
|
|
|
2
|
|
1293
|
use DBIx::LogAny::db; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
71
|
|
13
|
2
|
|
|
2
|
|
1402
|
use DBIx::LogAny::st; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
2341
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
16
|
|
|
|
|
|
|
require Exporter; |
17
|
|
|
|
|
|
|
our @ISA = qw(Exporter DBI); # look in DBI for anything we don't do |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our @EXPORT = (); # export nothing by default |
20
|
|
|
|
|
|
|
our @EXPORT_MASKS = qw(DBIX_LA_LOG_DEFAULT |
21
|
|
|
|
|
|
|
DBIX_LA_LOG_ALL |
22
|
|
|
|
|
|
|
DBIX_LA_LOG_INPUT |
23
|
|
|
|
|
|
|
DBIX_LA_LOG_OUTPUT |
24
|
|
|
|
|
|
|
DBIX_LA_LOG_CONNECT |
25
|
|
|
|
|
|
|
DBIX_LA_LOG_TXN |
26
|
|
|
|
|
|
|
DBIX_LA_LOG_ERRCAPTURE |
27
|
|
|
|
|
|
|
DBIX_LA_LOG_WARNINGS |
28
|
|
|
|
|
|
|
DBIX_LA_LOG_ERRORS |
29
|
|
|
|
|
|
|
DBIX_LA_LOG_DBDSPECIFIC |
30
|
|
|
|
|
|
|
DBIX_LA_LOG_DELAYBINDPARAM |
31
|
|
|
|
|
|
|
DBIX_LA_LOG_SQL |
32
|
|
|
|
|
|
|
DBIX_LA_LOG_STORE |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
our %EXPORT_TAGS= (masks => \@EXPORT_MASKS); |
35
|
|
|
|
|
|
|
Exporter::export_ok_tags('masks'); # all tags must be in EXPORT_OK |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub _dbix_la_debug { |
38
|
0
|
|
|
0
|
|
|
my ($self, $h, $level, $thing, @args) = @_; |
39
|
|
|
|
|
|
|
|
40
|
0
|
0
|
|
|
|
|
$h = $self->{private_DBIx_LogAny} if !defined($h); |
41
|
|
|
|
|
|
|
|
42
|
0
|
0
|
|
|
|
|
return unless $h->{logger}->is_debug(); |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
local $Data::Dumper::Indent = 0; |
45
|
0
|
|
|
|
|
|
local $Data::Dumper::Quotekeys = 0; |
46
|
|
|
|
|
|
|
|
47
|
0
|
0
|
|
|
|
|
if (scalar(@args) > 1) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
$h->{logger}->debug( |
49
|
|
|
|
|
|
|
Data::Dumper->Dump([\@args], [$thing])) |
50
|
|
|
|
|
|
|
} elsif (ref($thing) eq 'CODE') { |
51
|
0
|
|
|
|
|
|
$h->{logger}->debug($thing); |
52
|
|
|
|
|
|
|
} elsif (ref($args[0])) { |
53
|
0
|
|
|
|
|
|
$h->{logger}->debug( |
54
|
|
|
|
|
|
|
Data::Dumper->Dump([$args[0]], [$thing])) |
55
|
|
|
|
|
|
|
} elsif (scalar(@args) == 1) { |
56
|
0
|
0
|
|
|
|
|
if (!defined($args[0])) { |
57
|
0
|
|
|
|
|
|
$h->{logger}->debug("$thing:"); |
58
|
|
|
|
|
|
|
} else { |
59
|
0
|
|
|
|
|
|
$h->{logger}->debug("$thing: " . DBI::neat($args[0])); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} else { |
62
|
0
|
|
|
|
|
|
$h->{logger}->debug($thing); |
63
|
|
|
|
|
|
|
} |
64
|
0
|
|
|
|
|
|
return; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub _dbix_la_info { |
68
|
0
|
|
|
0
|
|
|
my ($self, $level, $thing) = @_; |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
my $h = $self->{private_DBIx_LogAny}; |
71
|
|
|
|
|
|
|
|
72
|
0
|
0
|
|
|
|
|
return unless $h->{logger}->is_info(); |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
$h->{logger}->info($thing); |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
return; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
sub _dbix_la_warning { |
79
|
0
|
|
|
0
|
|
|
my ($self, $level, $thing, @args) = @_; |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
my $h = $self->{private_DBIx_LogAny}; |
82
|
|
|
|
|
|
|
|
83
|
0
|
0
|
|
|
|
|
return unless $h->{logger}->is_warn(); |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
local $Data::Dumper::Indent = 0; |
86
|
0
|
|
|
|
|
|
local $Data::Dumper::Quotekeys = 0; |
87
|
|
|
|
|
|
|
|
88
|
0
|
0
|
|
|
|
|
if (scalar(@args) > 1) { |
|
|
0
|
|
|
|
|
|
89
|
0
|
|
|
0
|
|
|
$h->{logger}->warn( |
90
|
|
|
|
|
|
|
sub {Data::Dumper->Dump([\@args], [$thing])}) |
91
|
0
|
|
|
|
|
|
} elsif (ref($args[0])) { |
92
|
0
|
|
|
0
|
|
|
$h->{logger}->warn( |
93
|
|
|
|
|
|
|
sub {Data::Dumper->Dump([$args[0]], [$thing])}) |
94
|
0
|
|
|
|
|
|
} else { |
95
|
0
|
|
|
|
|
|
$h->{logger}->warn("$thing: " . DBI::neat($args[0])); |
96
|
|
|
|
|
|
|
} |
97
|
0
|
|
|
|
|
|
return; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub _dbix_la_error { |
101
|
0
|
|
|
0
|
|
|
my ($self, $level, $thing, @args) = @_; |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
my $h = $self->{private_DBIx_LogAny}; |
104
|
|
|
|
|
|
|
|
105
|
0
|
0
|
|
|
|
|
return unless $h->{logger}->is_error(); |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
local $Data::Dumper::Indent = 0; |
108
|
0
|
|
|
|
|
|
local $Data::Dumper::Quotekeys = 0; |
109
|
|
|
|
|
|
|
|
110
|
0
|
0
|
|
|
|
|
if (scalar(@args) > 1) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
111
|
0
|
|
|
0
|
|
|
$h->{logger}->error( |
112
|
|
|
|
|
|
|
sub {Data::Dumper->Dump([\@args], [$thing])}) |
113
|
0
|
|
|
|
|
|
} elsif (ref($thing) eq 'CODE') { |
114
|
0
|
|
|
|
|
|
$h->{logger}->error($thing); |
115
|
|
|
|
|
|
|
} elsif (ref($args[0])) { |
116
|
0
|
|
|
0
|
|
|
$h->{logger}->error( |
117
|
|
|
|
|
|
|
sub {Data::Dumper->Dump([$args[0]], [$thing])}) |
118
|
0
|
|
|
|
|
|
} else { |
119
|
0
|
|
|
|
|
|
$h->{logger}->error("$thing: " . DBI::neat($args[0])); |
120
|
|
|
|
|
|
|
} |
121
|
0
|
|
|
|
|
|
return; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub _dbix_la_attr_map { |
125
|
|
|
|
|
|
|
return { |
126
|
0
|
|
|
0
|
|
|
dbix_la_logmask => 'logmask', |
127
|
|
|
|
|
|
|
dbix_la_ignore_err_regexp => 'err_regexp', |
128
|
|
|
|
|
|
|
dbix_la_category => 'category', |
129
|
|
|
|
|
|
|
dbix_la_logger => 'logger' |
130
|
|
|
|
|
|
|
}; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub dbix_la_getattr { |
134
|
0
|
|
|
0
|
1
|
|
my ($self, $item) = @_; |
135
|
|
|
|
|
|
|
|
136
|
0
|
0
|
0
|
|
|
|
croak ('wrong arguments - dbix_la_getattr(attribute_name)') |
137
|
|
|
|
|
|
|
if (scalar(@_) != 2 || !defined($_[1])); |
138
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
my $m = _dbix_la_attr_map(); |
140
|
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
|
my $h = $self->{private_DBIx_LogAny}; |
142
|
|
|
|
|
|
|
|
143
|
0
|
0
|
|
|
|
|
if (!exists($m->{$item})) { |
144
|
0
|
|
|
|
|
|
warn "$item does not exist"; |
145
|
0
|
|
|
|
|
|
return; |
146
|
|
|
|
|
|
|
} |
147
|
0
|
|
|
|
|
|
return $h->{$m->{$item}}; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub dbix_la_setattr { |
151
|
0
|
|
|
0
|
1
|
|
my ($self, $item, $value) = @_; |
152
|
|
|
|
|
|
|
|
153
|
0
|
0
|
0
|
|
|
|
croak ('wrong arguments - dbix_la_setattr(attribute_name, value)') |
154
|
|
|
|
|
|
|
if (scalar(@_) != 3 || !defined($_[1])); |
155
|
|
|
|
|
|
|
|
156
|
0
|
|
|
|
|
|
my $m = _dbix_la_attr_map(); |
157
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
|
my $h = $self->{private_DBIx_LogAny}; |
159
|
|
|
|
|
|
|
|
160
|
0
|
0
|
|
|
|
|
if (!exists($m->{$item})) { |
161
|
0
|
|
|
|
|
|
warn "$item does not exist"; |
162
|
0
|
|
|
|
|
|
return; |
163
|
|
|
|
|
|
|
} |
164
|
0
|
|
|
|
|
|
$h->{$m->{$item}} = $value; |
165
|
0
|
|
|
|
|
|
1; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub connect { |
169
|
|
|
|
|
|
|
|
170
|
0
|
|
|
0
|
1
|
|
my ($drh, $dsn, $user, $pass, $attr) = @_; |
171
|
|
|
|
|
|
|
|
172
|
0
|
|
|
|
|
|
my $dbh = $drh->SUPER::connect($dsn, $user, $pass, $attr); |
173
|
0
|
0
|
|
|
|
|
return $dbh if (!$dbh); |
174
|
|
|
|
|
|
|
|
175
|
0
|
|
|
|
|
|
my $h = $dbh->{private_DBIx_LogAny}; |
176
|
|
|
|
|
|
|
|
177
|
0
|
0
|
|
|
|
|
if ($h->{logmask} & DBIX_LA_LOG_CONNECT) { |
178
|
0
|
|
|
|
|
|
local $Data::Dumper::Indent = 0; |
179
|
0
|
0
|
|
|
|
|
$h->{logger}->debug( |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
180
|
|
|
|
|
|
|
"connect($h->{dbh_no}): " . |
181
|
|
|
|
|
|
|
(defined($dsn) ? $dsn : '') . ', ' . |
182
|
|
|
|
|
|
|
(defined($user) ? $user : '') . ', ' . |
183
|
|
|
|
|
|
|
Data::Dumper->Dump([$attr], [qw(attr)])) |
184
|
|
|
|
|
|
|
if $h->{logger}->is_debug; |
185
|
2
|
|
|
2
|
|
14
|
no strict 'refs'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
577
|
|
186
|
0
|
|
|
|
|
|
my $v = "DBD::" . $dbh->{Driver}->{Name} . "::VERSION"; |
187
|
0
|
0
|
|
|
|
|
$h->{logger}->info("DBI: " . $DBI::VERSION, |
188
|
|
|
|
|
|
|
", DBIx::LogAny: " . $DBIx::LogAny::VERSION . |
189
|
|
|
|
|
|
|
", Driver: " . $h->{driver} . "(" . |
190
|
|
|
|
|
|
|
$$v . ")") |
191
|
|
|
|
|
|
|
if $h->{logger}->is_info; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
# |
195
|
|
|
|
|
|
|
# Enable dbms_output for DBD::Oracle else turn off DBDSPECIFIC as we have |
196
|
|
|
|
|
|
|
# no support for DBDSPECIFIC in any other drivers. |
197
|
|
|
|
|
|
|
# BUT only enable it if the log handle is doing debug as we only call |
198
|
|
|
|
|
|
|
# dbms_output_get in that case. |
199
|
|
|
|
|
|
|
# |
200
|
0
|
|
|
|
|
|
$h->{dbd_specific} = 1; |
201
|
0
|
0
|
0
|
|
|
|
if (($h->{logger}->is_debug()) && |
|
|
|
0
|
|
|
|
|
202
|
|
|
|
|
|
|
($h->{logmask} & DBIX_LA_LOG_DBDSPECIFIC) && |
203
|
|
|
|
|
|
|
($h->{driver} eq 'Oracle')) { |
204
|
0
|
|
|
|
|
|
$dbh->func('dbms_output_enable'); |
205
|
|
|
|
|
|
|
} else { |
206
|
0
|
|
|
|
|
|
$h->{logmask} &= ~DBIX_LA_LOG_DBDSPECIFIC; |
207
|
|
|
|
|
|
|
} |
208
|
0
|
|
|
|
|
|
$h->{dbd_specific} = 0; |
209
|
0
|
|
|
|
|
|
return $dbh; |
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
sub dbix_la_logdie |
213
|
|
|
|
|
|
|
{ |
214
|
0
|
|
|
0
|
1
|
|
my ($drh, $msg) = @_; |
215
|
0
|
|
|
|
|
|
_error_handler($msg, $drh); |
216
|
0
|
|
|
|
|
|
die "$msg"; |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
1; |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
__END__ |