📄 log.pm
字号:
C<Apache2::Log::Request> object to be used with L<LogLevelmethods|/LogLevel_Methods>.=item since: 2.0.00=back=head2 C<$r-E<gt>log_error>just logs the supplied message (similar toC<L<$s-E<gt>log_error|/C__s_E_gt_log_error_>> ). $r->log_error(@message);=over 4=item obj: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item arg1: C<@message> ( strings ARRAY )what to log=item ret: no return value=item since: 2.0.00=backFor example: $r->log_error("the request is about to end");=head2 C<$r-E<gt>log_reason>This function provides a convenient way to log errors in apreformatted way: $r->log_reason($message); $r->log_reason($message, $filename);=over 4=item obj: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item arg1: C<$message> ( string )the message to log=item opt arg2: C<$filename> ( string )where to report the error as coming from (e.g. C<__FILE__>)=item ret: no return value=item since: 2.0.00=backFor example: $r->log_reason("There is no enough data");will generate a log entry similar to the following: [Fri Sep 24 11:58:36 2004] [error] access to /someuri failed for 127.0.0.1, reason: There is no enough data.=head2 C<$r-E<gt>log_rerror>This function provides a fine control of when the message is logged,gives an access to built-in status codes. $r->log_rerror($file, $line, $level, $status, @message);arguments are identical toC<L<$s-E<gt>log_serror|/C__s_E_gt_log_serror_>>.=over 4=item since: 2.0.00=backFor example: use Apache2::Const -compile => qw(:log); use APR::Const -compile => qw(ENOTIME SUCCESS); $r->log_rerror(Apache2::Log::LOG_MARK, Apache2::Const::LOG_ERR, APR::Const::SUCCESS, "log_rerror logging at err level"); $r->log_rerror(Apache2::Log::LOG_MARK, Apache2::Const::LOG_DEBUG, APR::Const::ENOTIME, "debug print");=head2 C<$r-E<gt>warn> $r->warn(@warnings);is the same as: $r->log_error(Apache2::Log::LOG_MARK, Apache2::Const::LOG_WARNING, APR::Const::SUCCESS, @warnings)=over 4=item obj: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item arg1: C<@warnings> ( strings ARRAY )array of warning strings=item ret: no return value=item since: 2.0.00=backFor example: $r->warn('routine server warning');=head1 Other Logging Methods=head2 LogLevel Methodsafter getting the log handle with C<L<$s-E<gt>log|/C__s_E_gt_log_>> orC<L<$r-E<gt>log|/C__s_E_gt_log_>>, use one of the following methods(corresponding to the C<LogLevel> levels): emerg(), alert(), crit(), error(), warn(), notice(), info(), debug()to control when messages should be logged: $s->log->emerg(@message); $r->log->emerg(@message);=over 4=item obj: C<$slog> ( L<server|/C__s_E_gt_log_> orL<request|/C__s_E_gt_log_> log handle )=item arg1: C<@message> ( strings ARRAY )=item ret: no return value=item since: 2.0.00=backFor example if the C<LogLevel> is C<error> and the following code isexecuted: my $slog = $s->log; $slog->debug("just ", "some debug info"); $slog->warn(@warnings); $slog->crit("dying");only the last command's logging will be performed. This is becauseI<warn>, I<debug> and other logging command which are listed right toI<error> will be disabled.=head2 C<alert>See L<LogLevel Methods|/LogLevel_Methods>.=head2 C<crit>See L<LogLevel Methods|/LogLevel_Methods>.=head2 C<debug>See L<LogLevel Methods|/LogLevel_Methods>.=head2 C<emerg>See L<LogLevel Methods|/LogLevel_Methods>.=head2 C<error>See L<LogLevel Methods|/LogLevel_Methods>.=head2 C<info>See L<LogLevel Methods|/LogLevel_Methods>.=head2 C<notice>See L<LogLevel Methods|/LogLevel_Methods>.Though Apache treats C<notice()> calls as special. The message isalways logged regardless the value of C<ErrorLog>, unless the errorlog is set to use syslog. (For details see httpd-2.0/server/log.c.)=head2 C<warn>See L<LogLevel Methods|/LogLevel_Methods>.=head1 General Functions=head2 C<LOG_MARK>Though looking like a constant, this is a function, which returns alist of two items: C<(__FILE__, __LINE__)>, i.e. the file and the linewhere the function was called from. my ($file, $line) = Apache2::Log::LOG_MARK();=over 4=item ret1: C<$file> ( string )=item ret2: C<$line> ( number )=item since: 2.0.00=backIt's mostly useful to be passed as the first argument to those loggingmethods, expecting the filename and the line number as the firstarguments (e.g., C<L<$s-E<gt>log_serror|/C__s_E_gt_log_serror_>> andC<L<$r-E<gt>log_rerror|/C__r_E_gt_log_rerror_>> ).=head1 Virtual HostsCode running from within a virtual host needs to be able to log intoits C<ErrorLog> file, if different from the main log. Calling any ofthe logging methods on the C<$r> and C<$s> objects will do the loggingcorrectly.If the core C<warn()> is called, it'll be always logged to the mainlog file. Here is how to make it log into the vhost F<error_log> file.Let's say that we start with the following code: warn "the code is smoking";=over=item 1First, we need to use mod_perl's logging function, instead ofC<CORE::warn>Either replace C<warn> with C<Apache2::ServerRec::warn>: use Apache2::Log (); Apache2::ServerRec::warn("the code is smoking");or import it into your code: use Apache2::ServerRec qw(warn); # override warn locally warn "the code is smoking";or override C<CORE::warn>: use Apache2::Log (); *CORE::GLOBAL::warn = \&Apache2::ServerRec::warn; warn "the code is smoking";Avoid using the latter suggestion, since it'll affect all the coderunning on the server, which may break things. Of course you canlocalize that as well: use Apache2::Log (); local *CORE::GLOBAL::warn = \&Apache2::ServerRec::warn; warn "the code is smoking";Chances are that you need to make the internal Perl warnings go intothe vhost's F<error_log> file as well. Here is how to do that: use Apache2::Log (); local $SIG{__WARN__} = \&Apache2::ServerRec::warn; eval q[my $x = "aaa" + 1;]; # this issues a warningNotice that it'll override any previous setting you may have had,disabling modules like C<CGI::Carp> which also use C<$SIG{__WARN__}>=item 2Next we need to figure out how to get hold of the vhost's serverobject.Inside HTTP request handlers this is possible viaC<Apache2-E<gt>request|docs::2.0::api::Apache2::RequestUtil/C_request_>. Whichrequires either C<L<PerlOptions+GlobalRequest|docs::2.0::user::config::config/C_GlobalRequest_>>setting or can be also done at runtime if C<$r> is available: use Apache2::RequestUtil (); sub handler { my $r = shift; Apache2::RequestUtil->request($r); ...Outside HTTP handlers at the moment it is not possible, to get hold ofthe vhost's F<error_log> file. This shouldn't be a problem for thecode that runs only under mod_perl, since the always available C<$s>object can invoke a plethora of methods supplied byC<Apache2::Log>. This is only a problem for modules, which are supposedto run outside mod_perl as well.META: To solve this we think to introduce 'PerlOptions +GlobalServer',a big brother for 'PerlOptions +GlobalRequest', which will be set inmodperl_hook_pre_connection.=back=head1 Unsupported APIC<Apache2::Log> also provides auto-generated Perl interface for a fewother methods which aren't tested at the moment and therefore theirAPI is a subject to change. These methods will be finalized later as aneed arises. If you want to rely on any of the following methodsplease contact the L<the mod_perl development mailinglist|maillist::dev> so we can help each other take the steps necessaryto shift the method to an officially supported API.=head2 C<log_pid>META: what is this method good for? it just calls getpid and logsit. In any case it has nothing to do with the logging API. And it usesstatic variables, it probably shouldn't be in the Apache public API.Log the current pid Apache2::Log::log_pid($pool, $fname);=over 4=item obj: C<$p> ( C<L<APR::Pool object|docs::2.0::api::APR::Pool>> )The pool to use for logging=item arg1: C<$fname> ( file path )The name of the file to log to=item ret: no return value=item since: subject to change=back=head1 See AlsoL<mod_perl 2.0 documentation|docs::2.0::index>.=head1 Copyrightmod_perl 2.0 and its core modules are copyrighted underThe Apache Software License, Version 2.0.=head1 AuthorsL<The mod_perl development team and numerouscontributors|about::contributors::people>.=cut
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -