Apache2::LogUtil - Simple logging API with run-time context
use Apache2::LogUtil; my $log = Apache2::LogUtil->new();
Or, to capture elapsed time:
use Apache2::LogUtil; use Misc::Stopwatch; my $sw = Misc::Stopwatch->new; my $log = Apache2::LogUtil->new($sw);
In a perl handler, initialize the objects on each request:
$sw->reset->start(); # Elapsed time starts now $log->set_request(); # Will use $s-log_serror> (Server log file) $log->set_request($r); # Will use $r-log_rerror> (VirtualHost log file)
Call logging methods:
$log->error('The code is smoking'); $log->warn('The code is hot'); $log->notice('The code is warm'); $log->info('The code is lighting up'); $log->debug('The code is doing what?');
Nothing exported by default
This module requires these other modules and libraries:
Apache2::Const Apache2::Log Apache2::ServerUtil APR::Const Apache2::MPM APR::OS
Calls $s->log_serror or $r->log_rerror if a $r has been passed to "set_request". Log-file entries are formatted as:
$s->log_serror
$r->log_rerror
$r
Fieldset 1 - Inserted by Apache Fieldset 2 - Inserted by this module Fieldset 3 - Inserted by this module Fieldset 4 - The log message .----------------------------------------- 1a) Apache date/time stamp | .----------------------------------- 1b) Logging level | | | | .---------------------------- 2) HTTP Request Cycle Phase | | | .------------------ 3a) Process ID, i.e., $$ | | | | .------------ 3b) Thread ID (for threaded perl), or 0 | | | | | .---------- 3c) Elapsed time, or 0 | | | | | | .-- 4) Log Message | | | | | | | | | | | | | | v v v v v v v [...] [warn] <Cleanup> [22933-0:0.0229] ... ^------------------------^ (inserted by this module) 1) Log prefix as per your Apache configuration, normally these values are: 1a) The date and time of the request. 1b) The log level of the message. The Apache directive LogLevel determines which messages are displayed. 2) The phase name is a shortened form of the current callback name. As in the above example, the callback name PerlCleanupHandler is trimmed by removing the and the leading Perl and trailing Handler. 3) Process information 3a) As in $$ 3b) ID of the child thread of $$. If not running with threads, zero. 3c) Elapsed time if a Misc::Stopwatch has been set up, otherwise zero. 4) The message which we're here to log
new new $stopwatch new $stopwatch $request
where:
$stopwatch isa Misc::Stopwatch $request isa Apache2::RequestRec
debug $message
warn $warn
error $error
notice $notice
info $message
message $LOG_TYPE, $message
Apache2::Testing::LogUtil Apache2::Trace Misc::Stopwatch http://perl.apache.org/docs/2.0/user/handlers/http.html#HTTP_Request_Cycle_Phases
Ryan Gies <ryangies@cpan.org>
Copyright (C) 2006-2010 by Livesite Networks, LLC. All rights reserved.
Copyright (C) 2000-2005 by Ryan Gies. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
* Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
* The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
To the best of our knowledge, no patented algorithms have been used. However, we do not have the resources to carry out a patent search, and therefore cannot give any guarantee of the above statement.
To install Misc::Stopwatch, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Misc::Stopwatch
CPAN shell
perl -MCPAN -e shell install Misc::Stopwatch
For more information on module installation, please visit the detailed CPAN module installation guide.