Log::Any::For::DBI - Add logging to DBI method calls, etc
This document describes version 0.10 of Log::Any::For::DBI (from Perl distribution Log-Any-For-DBI), released on 2015-08-17.
use DBI; use Log::Any::For::DBI; # now all connect()'s, do()'s, prepare()'s are logged with Log::Any my $dbh = DBI->connect("dbi:...", $user, $pass); $dbh->do("INSERT INTO table VALUES (...)");
Sample script and output:
% TRACE=1 perl -MLog::Any::App -MDBI -MLog::Any::For::DBI \ -e'$dbh=DBI->connect("dbi:SQLite:dbname=/tmp/tmp.db", "", ""); $dbh->do("CREATE TABLE IF NOT EXISTS t (i INTEGER)");' [1] ---> DBI::connect(['dbi:SQLite:dbname=/tmp/tmp.db','','********']) [5] <--- DBI::connect() = [bless( {}, 'DBI::db' )] [5] ---> DBI::db::do(['CREATE TABLE IF NOT EXISTS t (i INTEGER)']) [5] ---> DBI::db::prepare(['CREATE TABLE IF NOT EXISTS t (i INTEGER)',undef]) [5] <--- DBI::db::prepare() = [bless( {}, 'DBI::st' )] [5] ---> DBI::st::execute([]) [5] <--- DBI::st::execute() = ['0E0'] [5] <--- DBI::db::do()
You can filter to log only certain methods by passing the method names as import arguments, for example:
use Log::Any::For::DBI qw(prepare connect);
Log::Any::For::Class
DBIx::Log4perl, one of the inspirations for this module. With due respect to its author, I didn't like the approach of DBIx::Log4perl and its intricate links to DBI's internals. I'm sure DBIx::Log4perl is good at what it does, but currently I only need to log SQL statements.
Please visit the project's homepage at https://metacpan.org/release/Log-Any-For-DBI.
Source repository is at https://github.com/sharyanto/perl-Log-Any-For-DBI.
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Log-Any-For-DBI
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
perlancar <perlancar@cpan.org>
This software is copyright (c) 2015 by perlancar@cpan.org.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Log::Any::For::DBI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Log::Any::For::DBI
CPAN shell
perl -MCPAN -e shell install Log::Any::For::DBI
For more information on module installation, please visit the detailed CPAN module installation guide.