You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Brian Phillips <bp...@gmail.com> on 2005/11/10 18:54:19 UTC
@CustomLog and @LogFormat directives
I've been attempting to turn my httpd.conf file into a perl module. Overall,
it seems pretty straightforward but I've had trouble with the CustomLog and
LogFormat directives. I can get them to work as scalars but not as arrays.
For instance, the following works (it took me awhile to get anything to
work):
<Perl>
$LogFormat = '"%h %l %u %t \\"%r\\" %>s %b \\"%{Referer}i\\"
\\"%{User-Agent}i\\"" combined';
$CustomLog = 'logs/access_log combined';
</Perl>
But when I attempt to specify multiple values for either of those
directives, I either get a Apache error on startup or nothing gets written
to the logs.
Even simply just changing the LogFormat to an array and keeping the rest of
the data the same doesn't work:
<Perl>
@LogFormat = ('"%h %l %u %t \\"%r\\" %>s %b \\"%{Referer}i\\"
\\"%{User-Agent}i\\"" combined');
$CustomLog = 'logs/access_log combined';
</Perl>
In this instance, the word "combined" gets written to the access log which
seems to indicate the @LogFormat isn't getting parsed correctly. I've tried
changing the element to an array ref but that doesn't help either:
<Perl>
@LogFormat = (['"%h %l %u %t \\"%r\\" %>s %b \\"%{Referer}i\\"
\\"%{User-Agent}i\\""', 'combined']);
$CustomLog = 'logs/access_log combined';
</Perl>
Playing with the quoting hasn't seemed to get me anywhere either (the
following results in "<Perl>: LogFormat takes 1-2 arguments, a log format
string (see docs) and an optional format name."):
<Perl>
@LogFormat = (['%h %l %u %t \"%r\" %>s %b \"%{Referer}i\"
\"%{User-Agent}i\"', 'combined']);
$CustomLog = 'logs/access_log combined';
</Perl>
Even using Apache->httpd_conf with the exact line from our regular
httpd.conf hasn't worked:
<Perl>
Apache->httpd_conf(q{
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""
combined
});
our $CustomLog = 'logs/access_log combined';
</Perl>
I'd like to be able to do something like this:
<Perl>
@LogFormat = (
'"%h %l %u %t \\"%r\\" %>s %b \\"%{Referer}i\\" \\"%{User-Agent}i\\""
combined'],
'"%h %l %u %t \\"%r\\" %>s %b" common',
'"%{Referer}i -> %U" referer',
'%{User-agent}i agent',
);
@CustomLog = (
['logs/access_log', 'common'],
['logs/referer_log', 'referer'],
['logs/agent_log', 'agent'],
);
</Perl>
Does anyone have a working example of how to use multiple values for these
specific directives?
Thanks in advance,
Brian
Re: @CustomLog and @LogFormat directives
Posted by Frank Wiles <fr...@wiles.org>.
On Thu, 10 Nov 2005 11:54:19 -0600
Brian Phillips <bp...@gmail.com> wrote:
> I'd like to be able to do something like this:
> <Perl>
> @LogFormat = (
> '"%h %l %u %t \\"%r\\" %>s %b \\"%{Referer}i\\" \\"%{User-Agent}i\\""
> combined'],
> '"%h %l %u %t \\"%r\\" %>s %b" common',
> '"%{Referer}i -> %U" referer',
> '%{User-agent}i agent',
> );
>
> @CustomLog = (
> ['logs/access_log', 'common'],
> ['logs/referer_log', 'referer'],
> ['logs/agent_log', 'agent'],
> );
>
> </Perl>
>
> Does anyone have a working example of how to use multiple values for
> these specific directives?
Try this patch and let me know if it works for you.
---------------------------------
Frank Wiles <fr...@wiles.org>
http://www.wiles.org
---------------------------------
Re: @CustomLog and @LogFormat directives
Posted by Brian Phillips <bp...@gmail.com>.
Unfortunately I'm not using Apache2... :-(
Any ideas for Apache 1.3?
On 10 Nov 2005 11:37:50 -0800, Randal L. Schwartz <me...@stonehenge.com>
wrote:
>
> >>>>> "Brian" == Brian Phillips <bp...@gmail.com> writes:
>
> Brian> Even using Apache->httpd_conf with the exact line from our regular
> Brian> httpd.conf hasn't worked:
> Brian> <Perl>
> Apache-> httpd_conf(q{
> Brian> LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\"
> \"%{User-Agent}i\""
> Brian> combined
> Brian> });
> Brian> our $CustomLog = 'logs/access_log combined';
> Brian> </Perl>
>
> Brian> Does anyone have a working example of how to use multiple values
> for these
> Brian> specific directives?
>
> This is probably an example of the bug I reported earlier, and to which a
> fix has been posted, but not tested. However, my workaround looks like
> this:
>
> <Perl>
> use Apache2::PerlSections;
> BEGIN {
> *Apache2::PerlSections::dump_special = sub {
> my($self, @data) = @_;
> $self->add_config($_) for @data;
> }
> }
> </Perl>
>
> And that works for me to enable PerlSections to actually *work*.
> Apparently, there are no tests for that. :(
>
> --
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777
> 0095
> <me...@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
> See PerlTraining.Stonehenge.com <http://PerlTraining.Stonehenge.com> for
> onsite and open-enrollment Perl training!
>
Re: @CustomLog and @LogFormat directives
Posted by "Randal L. Schwartz" <me...@stonehenge.com>.
>>>>> "Brian" == Brian Phillips <bp...@gmail.com> writes:
Brian> Even using Apache->httpd_conf with the exact line from our regular
Brian> httpd.conf hasn't worked:
Brian> <Perl>
Apache-> httpd_conf(q{
Brian> LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""
Brian> combined
Brian> });
Brian> our $CustomLog = 'logs/access_log combined';
Brian> </Perl>
Brian> Does anyone have a working example of how to use multiple values for these
Brian> specific directives?
This is probably an example of the bug I reported earlier, and to which a
fix has been posted, but not tested. However, my workaround looks like this:
<Perl>
use Apache2::PerlSections;
BEGIN {
*Apache2::PerlSections::dump_special = sub {
my($self, @data) = @_;
$self->add_config($_) for @data;
}
}
</Perl>
And that works for me to enable PerlSections to actually *work*.
Apparently, there are no tests for that. :(
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<me...@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!