NAME

DBIx::QueryLog - Logging queries for DBI

SYNOPSIS

use DBIx::QueryLog;
my $row = $dbh->selectrow_hashref('SELECT * FROM people WHERE user_id = ?', undef, qw/1986/);
# => SELECT * FROM people WHERE user_id = '1986';

DESCRIPTION

DBIx::QueryLog is logs each execution time and the actual query.

Currently, works on DBD::mysql and DBD::sqlite.

CLASS METHODS

threshold

If exceed this value for logs. (default not set)

DBIx::QueryLog->threshold(0.1); # sec
probability

Run once every "set value" times. (default not set)

DBIx::QueryLog->probability(100); # about 1/100
logger

Sets logger class (e.g. Log::Dispach)

Logger class must can be call `log` method.

DBIx::QueryLog->logger($logger);
skip_bind

If enabled, will be faster.

But SQL is not bind. The statement and bind-params are logs separately.

DBIx::QueryLog->skip_bind(1);
my $row = $dbh->do(...);
# => 'SELECT * FROM people WHERE user_id = ?' : [1986]
color

If you want to colored SQL output are:

DBIx::QueryLog->color('green');

And, you can also specify DBIX_QUERYLOG_COLOR environment variable.

useqq

using $Data::Dumper::Useqq.

DBIx::QueryLog->useqq(1);

And, you can also specify DBIX_QUERYLOG_USEQQ environment variable.

compress

Compress SQL using SQL::Tokenizer.

DBIx::QueryLog->compress(1);
#  FROM: SELECT          *  FROM      foo WHERE bar = 'baz'
#  TO  : SELECT * FROM foo WHERE bar = 'baz'

And, you can also specify DBIX_QUERYLOG_COMPRESS environment variable.

begin

SEE ALSO "Localization"

end

SEE ALSO "Localization"

TIPS

Localization

If you want to localize the scope are:

use DBIx::QueryLog (); # or require DBIx::QueryLog;

DBIx::QueryLog->begin;
my $row = $dbh->do(...);
DBIx::QueryLog->end;

Now you could enable logging between `begin` and `end`.

LOG_LEVEL

If you want to change log_level are:

$DBIx::QueryLog::LOG_LEVEL = 'info'; # default 'debug'

OUTPUT

If you want to change log output are:

open my $fh, '>', 'dbix_query.log';
$DBIx::QueryLog::OUTPUT = $fh;

Default $OUTPUT is STDERR.

AUTHOR

xaicron <xaicron {at} cpan.org>

COPYRIGHT

Copyright 2010 - xaicron

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

DBI