perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Torsten Förtsch <>
Subject Re: Apache2::ModLogConfig help needed (feature suggestion)
Date Thu, 03 Mar 2011 08:42:46 GMT
On Thursday, March 03, 2011 07:43:54 Randolf Richardson wrote:
> > I am in the process of developing an interface to mod_log_config. It can
> > do 2 
> >
> > things:
> > 
> >
> > * make CustomLog call perl handlers
> > * work as a log drain or log file
> [sNip]
> > BTW, if you feel urge to comment the idea or the implementation please
> > don't  hesitate.
>         What I think would be a very nice addition to that list of two 
> things is to be able to specify a customized filename for the log 
> files.  I'm unsure if this is even possible though.

Not taking into account the security implications this would be possible:

package My::LogWriter;
use Apache2::RequestRec ();
use Apache2::Const -compile=>'OK';

sub handler {
  my ($r, @string)=@_;

  my $filehandle=compute_filehandle_based_on_request_time($r->request_time);
  print $filehandle join '', @string;

  return Apache2::Const::OK;
PerlLoadModule Apache2::ModLogConfig
CustomLog "@perl: My::LogWriter" "format spec"

You even can use anonymous subs here. Thus, the handler can be made more 

CustomLog "@perl: sub {My::LogWriter::handler(q/%YYYY-%MM-%DD.log/, @_)}" \
          "format spec"

>         I currently pipe through "cronolog" to include the YEAR and MONTH 
> numbers in the filenames.  If this could be handled without piping 
> out to another process, then it would reduce a lot of pipe process 
> overhead (for each VirtualHost there are two "cronolog" processes, 
> one for the CustomLog, and the other for the ErrorLog).
>         An example of the filenames for log files for this month are 
> "access.2011-03.log" and "errors.2011-03.log."
>         If this feature is possible, then this module could also help to 
> make ModPerl 2 a little bit more popular if other administrators are 
> interested in reducing the number of piped processes.

I think it depends on the number of workers if this approach is really better.

Why don't you log an VHost ID as well and and use exactly 1 reader? Don't know 
if cronolog can do that but generally you can use the additional ID to split 
the log into parts for each VHost. That way the opening and file name guessing 
is done in one place.

Anyway, the reason for me to implement this was to get hands on values that 
are otherwise really hard to get. mod_logio measures the number of bytes that 
come in an go out on the wire for each request. For the input it installs a 
network level filter. Modperl implements only connection and request level 
filters. But the output counting is done by the core output filter and 
reported to mod_logio by means of an optional function. So, measuring these 
values in perl is impossible.

Now with this module I can do (provided mod_perl, mod_log_config and mod_logio 
are loaded)

package My::IO;
use Apache2::RequestRec ();
use Apache2::Const -compile=>'OK';

sub handler {
  my ($r, $inbytes, $outbytes)=@_;

  $r->pnotes->{inout}=[$inbytes, $outbytes];

  return Apache2::Const::OK;
PerlLoadModule Apache2::ModLogConfig
CustomLog "@perl: My::IO" "%I%O"

A request pool cleanup handler for example would then be able to use the 

Torsten Förtsch

Need professional modperl support? Hire me! (

Like fantasy?

View raw message