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
- <Perl> @CustomLog and @LogFormat directives Brian Phillips
- Re: <Perl> @CustomLog and @LogFormat directi... Randal L. Schwartz
- Re: <Perl> @CustomLog and @LogFormat dir... Brian Phillips
- Re: <Perl> @CustomLog and @LogFormat directi... Frank Wiles