📄 log.pm
字号:
# # /*# * *********** WARNING **************# * This file generated by ModPerl::WrapXS/0.01# * Any changes made here will be lost# * ***********************************# * 01: lib/ModPerl/Code.pm:708# * 02: lib/ModPerl/WrapXS.pm:624# * 03: lib/ModPerl/WrapXS.pm:1173# * 04: Makefile.PL:423# * 05: Makefile.PL:325# * 06: Makefile.PL:56# */# package Apache2::Log;use strict;use warnings FATAL => 'all';use Apache2::XSLoader ();our $VERSION = '2.000002';Apache2::XSLoader::load __PACKAGE__;1;__END__=head1 NAMEApache2::Log - Perl API for Apache Logging Methods=head1 Synopsis # in startup.pl #-------------- use Apache2::Log; use Apache2::Const -compile => qw(OK :log); use APR::Const -compile => qw(:error SUCCESS); my $s = Apache2::ServerUtil->server; $s->log_error("server: log_error"); $s->log_serror(__FILE__, __LINE__, Apache2::Const::LOG_ERR, APR::Const::SUCCESS, "log_serror logging at err level"); $s->log_serror(Apache2::Log::LOG_MARK, Apache2::Const::LOG_DEBUG, APR::Const::ENOTIME, "debug print"); Apache2::ServerRec->log_error("routine warning"); Apache2::ServerRec::warn("routine warning"); # in a handler #------------- package Foo; use strict; use warnings FATAL => 'all'; use Apache2::Log; use Apache2::Const -compile => qw(OK :log); use APR::Const -compile => qw(:error SUCCESS); sub handler { my $r = shift; $r->log_error("request: log_error"); my $rlog = $r->log; for my $level qw(emerg alert crit error warn notice info debug) { no strict 'refs'; $rlog->$level($package, "request: $level log level"); } # can use server methods as well my $s = $r->server; $s->log_error("server: log_error"); $r->log_rerror(Apache2::Log::LOG_MARK, Apache2::Const::LOG_DEBUG, APR::Const::ENOTIME, "in debug"); $s->log_serror(Apache2::Log::LOG_MARK, Apache2::Const::LOG_INFO, APR::Const::SUCCESS, "server info"); $s->log_serror(Apache2::Log::LOG_MARK, Apache2::Const::LOG_ERR, APR::Const::ENOTIME, "fatal error"); $r->log_reason("fatal error"); $r->warn('routine request warning'); $s->warn('routine server warning'); return Apache2::Const::OK; } 1; # in a registry script # httpd.conf: PerlOptions +GlobalRequest use Apache2::ServerRec qw(warn); # override warn locally print "Content-type: text/plain\n\n"; warn "my warning";=head1 DescriptionC<Apache2::Log> provides the Perl API for Apache logging methods.Depending on the the current C<LogLevel> setting, only logging withthe same log level or higher will be loaded. For example if thecurrent C<LogLevel> is set to I<warning>, only messages with log levelof the level I<warning> or higher (I<err>, I<crit>, I<elert> andI<emerg>) will be logged. Therefore this: $r->log_rerror(Apache2::Log::LOG_MARK, Apache2::Const::LOG_WARNING, APR::Const::ENOTIME, "warning!");will log the message, but this one won't: $r->log_rerror(Apache2::Log::LOG_MARK, Apache2::Const::LOG_INFO, APR::Const::ENOTIME, "just an info");It will be logged only if the server log level is set to I<info> orI<debug>. C<LogLevel> is set in the configuration file, but can bechanged using theC<L<$s-E<gt>loglevel()|docs::2.0::api::Apache2::ServerRec/C_loglevel_>>method.The filename and the line number of the caller are logged only ifC<Apache2::Const::LOG_DEBUG> is used (because that's how Apache 2.0 loggingmechanism works).Note: On Win32 Apache attempts to lock all writes to a file wheneverit's opened for append (which is the case with logging functions), asUnix has this behavior built-in, while Win32 does not. ThereforeC<Apache2::Log> functions could be slower than Perl's print()/warn().=head1 ConstantsLog level constants can be compiled all at once: use Apache2::Const -compile => qw(:log);or individually: use Apache2::Const -compile => qw(LOG_DEBUG LOG_INFO);=head2 LogLevel ConstantsThe following constants (sorted from the most severe level to theleast severe) are used in logging methods to specify the log level atwhich the message should be logged:=head3 C<Apache2::Const::LOG_EMERG>=head3 C<Apache2::Const::LOG_ALERT>=head3 C<Apache2::Const::LOG_CRIT>=head3 C<Apache2::Const::LOG_ERR>=head3 C<Apache2::Const::LOG_WARNING>=head3 C<Apache2::Const::LOG_NOTICE>=head3 C<Apache2::Const::LOG_INFO>=head3 C<Apache2::Const::LOG_DEBUG>=head2 Other ConstantsMake sure to compile the APR status constants before using them. Forexample to compile C<APR::Const::SUCCESS> and all the APR error statusconstants do: use APR::Const -compile => qw(:error SUCCESS);Here is the rest of the logging related constants:=head3 C<Apache2::Const::LOG_LEVELMASK>used to mask off the level value, to make sure that the log level'svalue is within the proper bits range. e.g.: $loglevel &= LOG_LEVELMASK;=head3 C<Apache2::Const::LOG_TOCLIENT>used to give content handlers the option of including the error textin the C<ErrorDocument> sent back to the client. WhenC<Apache2::Const::LOG_TOCLIENT> is passed to C<log_rerror()> the error messagewill be saved in the C<$r>'s notes table, keyed to the stringI<"error-notes">, if and only if the severity level of the message isC<Apache2::Const::LOG_WARNING> or greater and there are no otherI<"error-notes"> entry already set in the request record's notestable. Once the I<"error-notes"> entry is set, it is up to the errorhandler to determine whether this text should be sent back to theclient. For example: use Apache2::Const -compile => qw(:log); use APR::Const -compile => qw(ENOTIME); $r->log_rerror(Apache2::Log::LOG_MARK, Apache2::Const::LOG_ERR|Apache2::Const::LOG_TOCLIENT, APR::Const::ENOTIME, "request log_rerror");now the log message can be retrieved via: $r->notes->get("error-notes");Remember that client-generated text streams sent back to the clientB<MUST> be escaped to prevent CSS attacks.=head3 C<Apache2::Const::LOG_STARTUP>is useful for startup message where no timestamps, logging level iswanted. For example: use Apache2::Const -compile => qw(:log); use APR::Const -compile => qw(SUCCESS); $s->log_serror(Apache2::Log::LOG_MARK, Apache2::Const::LOG_INFO, APR::Const::SUCCESS, "This log message comes with a header");will print: [Wed May 14 16:47:09 2003] [info] This log message comes with a headerwhereas, when C<Apache2::Const::LOG_STARTUP> is binary ORed as in: use Apache2::Const -compile => qw(:log); use APR::Const -compile => qw(SUCCESS); $s->log_serror(Apache2::Log::LOG_MARK, Apache2::Const::LOG_INFO|Apache2::Const::LOG_STARTUP, APR::Const::SUCCESS, "This log message comes with no header");then the logging will be: This log message comes with no header=head1 Server Logging Methods=head2 C<$s-E<gt>log>get a log handle which can be used to L<log messages of differentlevels|/LogLevel_Methods>. my $slog = $s->log;=over 4=item obj: C<$s>( C<L<Apache2::ServerRec object|docs::2.0::api::Apache2::ServerRec>> )=item ret: C<$slog> ( C<Apache2::Log::Server> object )C<Apache2::Log::Server> object to be used with L<LogLevelmethods|/LogLevel_Methods>.=item since: 2.0.00=back=head2 C<$s-E<gt>log_error>just logs the supplied message to I<error_log> $s->log_error(@message);=over 4=item obj: C<$s>( C<L<Apache2::ServerRec object|docs::2.0::api::Apache2::ServerRec>> )=item arg1: C<@message> ( strings ARRAY )what to log=item ret: no return value=item since: 2.0.00=backFor example: $s->log_error("running low on memory");=head2 C<$s-E<gt>log_serror>This function provides a fine control of when the message is logged,gives an access to built-in status codes. $s->log_serror($file, $line, $level, $status, @message);=over 4=item obj: C<$s>( C<L<Apache2::ServerRec object|docs::2.0::api::Apache2::ServerRec>> )=item arg1: C<$file> ( string )The file in which this function is called=item arg2: C<$line> ( number )The line number on which this function is called=item arg3: C<$level>( C<L<Apache2::LOG_* constant|/LogLevel_Constants>> )The level of this error message=item arg4: C<$status>( C<L<APR::Const status constant|docs::2.0::api::APR::Const>> )The status code from the last command (similar to $! in perl), usuallyC<L<APR::Const constant|docs::2.0::api::APR::Const>> or coming from anL<exception object|docs::2.0::api::APR::Error>.=item arg5: C<@message> ( strings ARRAY )The log message(s)=item ret: no return value=item since: 2.0.00=backFor example: use Apache2::Const -compile => qw(:log); use APR::Const -compile => qw(ENOTIME SUCCESS); $s->log_serror(Apache2::Log::LOG_MARK, Apache2::Const::LOG_ERR, APR::Const::SUCCESS, "log_serror logging at err level"); $s->log_serror(Apache2::Log::LOG_MARK, Apache2::Const::LOG_DEBUG, APR::Const::ENOTIME, "debug print");=head2 C<$s-E<gt>warn> $s->warn(@warnings);is the same as: $s->log_error(Apache2::Log::LOG_MARK, Apache2::Const::LOG_WARNING, APR::Const::SUCCESS, @warnings)=over 4=item obj: C<$s>( C<L<Apache2::ServerRec object|docs::2.0::api::Apache2::ServerRec>> )=item arg1: C<@warnings> ( strings ARRAY )array of warning strings=item ret: no return value=item since: 2.0.00=backFor example: $s->warn('routine server warning');=head1 Request Logging Methods=head2 C<$r-E<gt>log>get a log handle which can be used to L<log messages of differentlevels|/LogLevel_Methods>. $rlog = $r->log;=over 4=item obj: C<$r> ( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item ret: C<$rlog> ( C<Apache2::Log::Request> object )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -