23 May 2018 19:39:12 UTC
- Distribution: DBI-Log
- Module version: 0.08
- Source (raw)
- Browse (raw)
- How to Contribute
- Testers (489 / 18 / 0)
- KwaliteeBus factor: 1
- 68.99% Coverage
- License: perl_5
- Perl: v5.6.0
- Activity24 month
- Download (4.2KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest version++ed by:1 non-PAUSE userJACOBG Jacob Gelbmanand 1 contributors
- Jacob Gelbman
DBI::Log - Log all DBI queries
You can use this module to log all queries that are made with DBI. You just need to include it in your script and it will work automatically. By default, it will send output to STDERR, which is useful for command line scripts and for CGI scripts since STDERR will appear in the error log.
If you want to log elsewhere, set the file option (on the use line) to a different location.
use DBI::Log file => "~/querylog.sql";
Each query in the log is prepended with the date and the place in the code where it was run from. You can add a full stack trace by setting the trace option (on the use line).
use DBI::Log trace => 1;
If you want timing information about how long the queries took to run add the timing option (on the use line).
use DBI::Log timing => 1;
The log is formatted as SQL, so if you look at it in an editor, it might be highlighted. This is what the output may look like:
-- Fri Sep 11 17:31:18 2015 -- execute t/test.t 18 CREATE TABLE foo (a INT, b INT) -- Fri Sep 11 17:31:18 2015 -- do t/test.t 21 INSERT INTO foo VALUES ('1', '2') -- Fri Sep 11 17:31:18 2015 -- selectcol_arrayref t/test.t 24 SELECT * FROM foo -- Fri Sep 11 17:31:18 2015 -- do t/test.t 27 -- (eval) t/test.t 27 INSERT INTO bar VALUES ('1', '2')
There is a built-in way to log with DBI, which can be enabled with DBI->trace(1), but the output is not easy to read through.
This module integrates placeholder values into the query, so the log will contain valid queries.
Jacob Gelbman, <firstname.lastname@example.org>
Árpád Szász, <email@example.com>
Copyright (C) 2015 by Jacob Gelbman
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.18.2 or, at your option, any later version of Perl 5 you may have available.