File Coverage

blib/lib/Log/Log4perl/JavaMap/JDBCAppender.pm
Criterion Covered Total %
statement 26 28 92.8
branch 1 4 25.0
condition 2 6 33.3
subroutine 3 3 100.0
pod 0 1 0.0
total 32 42 76.1


line stmt bran cond sub pod time code
1              
2             use Carp;
3 1     1   8 use strict;
  1         2  
  1         71  
4 1     1   6  
  1         2  
  1         427  
5             my ($class, $appender_name, $data) = @_;
6             my $stderr;
7 1     1 0 3  
8 1         2 my $pwd = $data->{password}{value} ||
9             die "'password' not supplied for appender '$appender_name', required for a '$data->{value}'\n";
10              
11 1   50     4 my $username = $data->{user}{value} ||
12             $data->{username}{value} ||
13             die "'user' not supplied for appender '$appender_name', required for a '$data->{value}'\n";
14              
15 1   0     4  
16             my $sql = $data->{sql}{value} ||
17             die "'sql' not supplied for appender '$appender_name', required for a '$data->{value}'\n";
18              
19 1   50     4  
20             my $dsn;
21              
22 1         1 my $databaseURL = $data->{URL}{value};
23             if ($databaseURL) {
24 1         2 $databaseURL =~ m|^jdbc:(.+?):(.+?)://(.+?):(.+?);(.+)|;
25 1 50       5 my $driverName = $1;
    0          
26 1         7 my $databaseName = $2;
27 1         4 my $hostname = $3;
28 1         4 my $port = $4;
29 1         3 my $params = $5;
30 1         4 $dsn = "dbi:$driverName:database=$databaseName;host=$hostname;port=$port;$params";
31 1         2 }elsif ($data->{datasource}{value}){
32 1         5 $dsn = $data->{datasource}{value};
33             }else{
34 0         0 die "'databaseURL' not supplied for appender '$appender_name', required for a '$data->{value}'\n";
35             }
36 0         0  
37              
38             #this part isn't supported by log4j, it's my Log4perl
39             #hack, but I think it's so useful I'm going to implement it
40             #anyway
41             my %bind_value_params;
42             foreach my $p (keys %{$data->{params}}){
43 1         2 $bind_value_params{$p} = $data->{params}{$p}{value};
44 1         2 }
  1         5  
45 4         10  
46             return Log::Log4perl::Appender->new("Log::Log4perl::Appender::DBI",
47             datasource => $dsn,
48             username => $username,
49             password => $pwd,
50             sql => $sql,
51             params => \%bind_value_params,
52             #warp_message also not a log4j thing, but see above
53             warp_message=> $data->{warp_message}{value},
54             );
55             }
56 1         11  
57             1;
58              
59             =encoding utf8
60              
61             =head1 NAME
62              
63             Log::Log4perl::JavaMap::JDBCAppender - wraps Log::Log4perl::Appender::DBI
64              
65             =head1 SYNOPSIS
66              
67              
68             =head1 DESCRIPTION
69              
70             Possible config properties for log4j JDBCAppender are
71              
72             bufferSize
73             sql
74             password
75             user
76             URL - attempting to translate a JDBC URL into DBI parameters,
77             let me know if you find problems
78              
79             Possible config properties for Log::Log4perl::Appender::DBI are
80              
81             bufferSize
82             sql
83             password
84             username
85             datasource
86            
87             usePreparedStmt 0|1
88            
89             (patternLayout).dontCollapseArrayRefs 0|1
90            
91            
92             =head1 SEE ALSO
93              
94             http://jakarta.apache.org/log4j/docs/
95              
96             Log::Log4perl::Javamap
97              
98             Log::Log4perl::Appender::DBI
99              
100             =head1 LICENSE
101              
102             Copyright 2002-2013 by Mike Schilli E<lt>m@perlmeister.comE<gt>
103             and Kevin Goess E<lt>cpan@goess.orgE<gt>.
104              
105             This library is free software; you can redistribute it and/or modify
106             it under the same terms as Perl itself.
107              
108             =head1 AUTHOR
109              
110             Please contribute patches to the project on Github:
111              
112             http://github.com/mschilli/log4perl
113              
114             Send bug reports or requests for enhancements to the authors via our
115              
116             MAILING LIST (questions, bug reports, suggestions/patches):
117             log4perl-devel@lists.sourceforge.net
118              
119             Authors (please contact them via the list above, not directly):
120             Mike Schilli <m@perlmeister.com>,
121             Kevin Goess <cpan@goess.org>
122              
123             Contributors (in alphabetical order):
124             Ateeq Altaf, Cory Bennett, Jens Berthold, Jeremy Bopp, Hutton
125             Davidson, Chris R. Donnelly, Matisse Enzer, Hugh Esco, Anthony
126             Foiani, James FitzGibbon, Carl Franks, Dennis Gregorovic, Andy
127             Grundman, Paul Harrington, Alexander Hartmaier David Hull,
128             Robert Jacobson, Jason Kohles, Jeff Macdonald, Markus Peter,
129             Brett Rann, Peter Rabbitson, Erik Selberg, Aaron Straup Cope,
130             Lars Thegler, David Viner, Mac Yang.
131