apache - Getting the request object outside a mod_perl handler -
i want log apache log file subroutine called mod_perl handler doesn't have request object ($r) .
sub handler { ($r) = shift; ... common::subroutine_that_also_logs(); ... } package common; sub subroutine_that_also_logs { ... # $r->log->info('cannot this') ... } while using print stderr or warn works want use apache2::log additional request information in log :-
[fri may 30 16:12:37 2014] [info] [client 123.123.123.123] cannot instead of
cannot i want avoid global init in handler mean updating few hundred handlers :-
my $globalr; sub handler { $globalr = shift; ... common::subroutine_that_also_logs(); } package common; sub subroutine_that_also_logs { ... $globalr->log->info('can try this') ... } i have set single perlfixuphandler initializing $globalr wonder if there better way or if $r available directly other means.
you can use apache2::requestutil.
package common; use apache2::requestrec; use apache2::requestutil; sub subroutine_that_also_logs { $r = apache2::requestutil->request; # process want using $r } if phase perlfixuphandler, $r has whole request information e.g. mime-type , on.
if use method, have write perloptions +globalrequest on httpd.conf apache httpd config file.
please see perldoc apache2::requestutil detail.
Comments
Post a Comment