DBIx-QueryLog
view release on metacpan or search on metacpan
lib/DBIx/QueryLog.pm view on Meta::CPAN
=item compact
If set, log messages will be compact.
DBIx::QueryLog->compact(1);
# FROM: SELECT * FROM foo WHERE bar = 'baz'
# TO : SELECT * FROM foo WHERE bar = 'baz'
You can also specify this with C<< DBIX_QUERYLOG_COMPACT >> environment variable.
=item explain
B<< EXPERIMENTAL >>
If set, DBIx::QueryLog logs the result of a C<< EXPLAIN >> statement.
DBIx::QueryLog->explain(1);
my $row = $dbh->do(...);
# => SELECT * FROM peaple WHERE user_id = '1986'
# .----------------------------------------------------------------------------------------------.
# | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
# +----+-------------+--------+-------+---------------+---------+---------+-------+------+-------+
# | 1 | SIMPLE | peaple | const | PRIMARY | PRIMARY | 4 | const | 1 | |
# '----+-------------+--------+-------+---------------+---------+---------+-------+------+-------'
You can also specify this with C<< DBIX_QUERYLOG_EXPLAIN >> environment variable.
=item show_data_source
if set, DBI data_source will be added to the log messages.
$dbh->do('SELECT * FROM sqlite_master');
# [2012-03-09T00:58:23] [main] [0.000953] SELECT * FROM sqlite_master at foo.pl line 34
DBIx::QueryLog->show_data_source(1);
$dbh->do('SELECT * FROM sqlite_master');
# [2012-03-09T00:58:23] [main] [0.000953] [SQLite:dbname=/tmp/TrSATdY3cc] SELECT * FROM sqlite_master at foo.pl line 56
You can also specify this with C<< DBIX_QUERYLOG_SHOW_DATASOURCE >> environment variable.
=item guard
Returns a guard object.
use DBIx::QueryLog ();
{
my $guard = DBIx::QueryLog->guard;
# ... do something
}
The following code does the same:
use DBIx::QueryLog ();
DBIx::QueryLog->enable;
# ... do something
DBIx::QueryLog->disable;
=item ignore_trace
Returns a guard object and disables tracing while the object is alive.
use DBIx::QueryLog;
# enabled
$dbh->do(...);
{
my $guard = DBIx::QueryLog->ignore_trace;
# disable
$dbh->do(...);
}
# enabled
$dbh->do(...)
=item is_enabled
Returns if DBIx::QueryLog is enabled or not.
use DBIx::QueryLog ();
say DBIx::QueryLog->is_enabled;
DBIx::QueryLog->disable;
See also L<< Localization >> section.
=back
=head1 TIPS
=head2 Localization
If you want to log only in a specific scope:
use DBIx::QueryLog (); # or require DBIx::QueryLog;
DBIx::QueryLog->begin; # or DBIx::QueryLog->enable
my $row = $dbh->do(...);
DBIx::QueryLog->end; # or DBIx::QueryLog->disable
DBIx::QueryLog logs only between C<< begin >> and C<< end >>.
=head2 LOG_LEVEL
When you set a C<< logger >>, you might also want to change a log level.
$DBIx::QueryLog::LOG_LEVEL = 'info'; # default 'debug'
=head2 OUTPUT
If you want to change where to output:
open my $fh, '>', 'dbix_query.log';
$DBIx::QueryLog::OUTPUT = $fh;
You can also specify a code reference:
$DBIx::QueryLog::OUTPUT = sub {
my %params = @_;
( run in 0.511 second using v1.01-cache-2.11-cpan-39bf76dae61 )