Show Contents Previous Page Next Page Chapter 9 - Perl API Reference Guide / The Apache Request Object In this section...
This section covers request object methods that generate entries in the server error log. They are handy for debugging and error reporting. Prior to Apache 1.3, the error-logging API was a very simple one that didn't distinguish between different levels of severity. Apache now has a more versatile logging API similar to the Unix syslog system.4 Each entry is associated with a severity level from low (debug) to high (critical). By adjusting the value of the LogLevel directive, the webmaster can control which error messages are recorded to the error log file. First we cover the interface to the earlier API. Then we discuss the Apache::Log class, which implements the 1.3 interface. Show Contents Go to Top Previous Page Next Page
log_error()
$r->log_error("Can't open index.html $!");
[Tue Jul 21 16:28:51 1998] [error] Can't open index.html No such file or directory log_reason()
[$DATE] [error] access to $URI failed for $HOST, reason: $MESSAGE
$r->log_reason("Can't open index.html $!");
[Tue Jul 21 16:30:47 1998] [error] access to /perl/index.pl failed for w15.yahoo.com, reason: Can't open index.html No such file or directory
$r->log_reason("Can't open file $!", $r->filename);
warn()
$r->warn("Attempting to open index.html");
as_string()
$r->warn("HTTP dump:\n", $r->as_string); [Tue Jul 21 16:51:51 1998] [warn] HTTP dump: GET /perl/index.pl HTTP/1.0 User-Agent: lwp-request/1.32 Host: localhost:9008 200 OK Connection: close Content-Type: text/plainShow Contents Go to Top Previous Page Next Page Apache version 1.3 introduced the notion of a log level. There are eight log levels, ranging in severity from emerg to debug. When modules call the new API logging routines, they provide the severity level of the message. You can control which messages appear in the server error logging by adjusting a new LogLevel directive. Messages greater than or equal to the severity level given by LogLevel appear in the error log. Messages below the cutoff are discarded. The Apache::Log API provides eight methods named for each of the severity levels. Each acts like the request object's error_log() method, except that it logs the provided message using the corresponding severity level. In order to use the new logging methods, you must The methods described in this section can be called with one or more string arguments or a subroutine reference. If a subroutine reference is used, it is expected to return a string which will be used in the log message. The subroutine will only be invoked if the LogLevel is set to the given level or higher. This is most useful to provide verbose debugging information during development while saving CPU cycles during production.
log()
use Apache::Log (); my $log = $r->log; # messages will include client ip address my $log = $r->server->log; # message will not include client ip address emerg()
$log->emerg("Cannot open lock file!");
alert()
$log->alert("getpwuid: couldn't determine user name from uid");
crit()
$log->crit("Cannot open configuration database!");
error()
$log->error("Parse of script failed: $@");
warn()
$log->warn("No database host specified, using default"); notice()
$log->notice("Cannot connect to master database, trying slave $host");
info()
$log->info("CGI.pm version is old, consider upgrading") if $CGI::VERSION < 2.42;
debug()
$log->debug("Reading configuration from file $fname"); $log->debug(sub { "The request: " . $r->as_string; });Show Contents Go to Top Previous Page Next Page Copyright © 1999 by O'Reilly & Associates, Inc. |
HIVE: All information for read only. Please respect copyright! |