You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Peter W <pe...@usa.net> on 1999/09/27 17:25:54 UTC
[PATCH] mod_log_config: expose r->protocol, r->method
For a recent project, we wanted to customize the log format and realized
that while %r refers to the full request line and %U refers to the uri,
there was no good way to refer to the method or protocol. Since the
request structure already has protocol and method members, I added code to
src/modules/standard/mod_log_config.c to add % LogFormat shortcuts:
%m => r->method (mnemonic: "m" for "method")
%H => r->protocol (mnemonic: "H" begins "HTTP/1.0")
The attached patch is a diff -c against the source for mod_log_config.c in
the latest CVS tarball
(http://dev.apache.org/from-cvs/apache-1.3/apache-1.3_19990927131226.tar.gz)
-Peter Watkins
*** mod_log_config.c.cvs19990927131226 Mon Sep 27 10:51:42 1999
--- mod_log_config.c Mon Sep 27 10:52:02 1999
***************
*** 334,339 ****
--- 334,347 ----
{
return r->uri;
}
+ static const char *log_request_method(request_rec *r, char *a)
+ {
+ return r->method;
+ }
+ static const char *log_request_protocol(request_rec *r, char *a)
+ {
+ return r->protocol;
+ }
static const char *log_status(request_rec *r, char *a)
{
return pfmt(r->pool, r->status);
***************
*** 505,510 ****
--- 513,524 ----
},
{
'P', log_child_pid, 0
+ },
+ {
+ 'H', log_request_protocol, 0
+ },
+ {
+ 'm', log_request_method, 0
},
{
'\0'
Re: [PATCH] mod_log_config: expose r->protocol, r->method
Posted by Peter W <pe...@usa.net>.
Adam,
You're right that the ? is only a delimiter; obviously I'm more concerned
about making a normal-looking log for analysis packages, especially
closed-source ones, so I'd prefer the ? to be prepended. A LogFormat
shortcut without the ? would mean adding a ? in the LogFormat, which might
upset some of these tools if Apache logged uri's with trailing ? but no
query string data.
Does it make sense to add _two_ shortcuts,
%q == "" || "?" + r->args /* traditional %r content */
%Q == "-" || r->args /* for logging separately? */
or is that treading on code-bloat? If two is too many, well, which is
preferable? I honestly don't have any use for the more "correct" shortcut,
even if it is more precise and faster/cleaner to code (e.g. no
ap_strcat() needed).
I'd like to hear from anyone (off-list?) who has had success with the
documented %{FOOBAR}e shortcut. I would have expected that to allow
something like %{QUERY_STRING}e to do what Adam wants, but I have had no
luck with %{...}e at all.
Thanks,
-Peter
At 6:21pm Sep 27, 1999, Adam M Donahue wrote:
> I would not include the question mark as part of the query string. If
> your intention is to reconstruct the URL in the log, then you should place
> the question mark in there specifically. According to rfc2396, the query
> component doesn't include the question mark; instead the mark is used as a
> delimiter.
> > Very good point. For this application, we didn't need to record the query
> > string, but I had also forgotten about it. Hmmm, how about %q for
> > query_string, generated by
> >
> > static const char *log_query_string(request_rec *r, char *a)
> > {
> > return (r->args != NULL) ? ap_pstrcat(r->pool, "?", r->args, NULL)
> > : "";
> > }
> >
> > so that "%m %U%q %H" == "%r", and the logging module would prepend "?" if
> > there was data, or log an empty char (i.e., nothing) if no query_string.
> >
> > -Peter
> >
> > At 12:39pm Sep 27, 1999, Spidaman The Defenestrator wrote:
> >
> > > The full request line would have the uri and the query string so having a
> > > log format that has "%m %U %H" would not replace %r, right?
> > >
> > > Meanwhile, back at the ranch...
> > > > For a recent project, we wanted to customize the log format and realized
> > > > that while %r refers to the full request line and %U refers to the uri,
> > > > there was no good way to refer to the method or protocol.
> >
> > > > %m => r->method (mnemonic: "m" for "method")
> > > > %H => r->protocol (mnemonic: "H" begins "HTTP/1.0")
> >
> >
> >
> >
>
The Intel Pentium III chip: designed to deny your privacy
Boycott Intel. http://www.privacy.org/bigbrotherinside/
Re: [PATCH] mod_log_config: expose r->protocol, r->method
Posted by Adam M Donahue <am...@acf3.nyu.edu>.
I would not include the question mark as part of the query string. If
your intention is to reconstruct the URL in the log, then you should place
the question mark in there specifically. According to rfc2396, the query
component doesn't include the question mark; instead the mark is used as a
delimiter.
Adam
> Very good point. For this application, we didn't need to record the query
> string, but I had also forgotten about it. Hmmm, how about %q for
> query_string, generated by
>
> static const char *log_query_string(request_rec *r, char *a)
> {
> return (r->args != NULL) ? ap_pstrcat(r->pool, "?", r->args, NULL)
> : "";
> }
>
> so that "%m %U%q %H" == "%r", and the logging module would prepend "?" if
> there was data, or log an empty char (i.e., nothing) if no query_string.
>
> -Peter
>
> At 12:39pm Sep 27, 1999, Spidaman The Defenestrator wrote:
>
> > The full request line would have the uri and the query string so having a
> > log format that has "%m %U %H" would not replace %r, right?
> >
> > Meanwhile, back at the ranch...
> > > For a recent project, we wanted to customize the log format and realized
> > > that while %r refers to the full request line and %U refers to the uri,
> > > there was no good way to refer to the method or protocol.
>
> > > %m => r->method (mnemonic: "m" for "method")
> > > %H => r->protocol (mnemonic: "H" begins "HTTP/1.0")
>
>
>
>
Re: [PATCH] mod_log_config: expose r->protocol, r->method
Posted by Dirk-Willem van Gulik <di...@webweaving.org>.
On Mon, 27 Sep 1999, Peter W wrote:
>
> Very good point. For this application, we didn't need to record the query
> string, but I had also forgotten about it. Hmmm, how about %q for
> query_string, generated by
>
> static const char *log_query_string(request_rec *r, char *a)
> {
> return (r->args != NULL) ? ap_pstrcat(r->pool, "?", r->args, NULL)
> : "";
> }
>
> so that "%m %U%q %H" == "%r", and the logging module would prepend "?" if
> there was data, or log an empty char (i.e., nothing) if no query_string.
Do I see a patch ?
:-)
DW
Re: [PATCH] mod_log_config: expose r->protocol, r->method
Posted by Peter W <pe...@usa.net>.
Very good point. For this application, we didn't need to record the query
string, but I had also forgotten about it. Hmmm, how about %q for
query_string, generated by
static const char *log_query_string(request_rec *r, char *a)
{
return (r->args != NULL) ? ap_pstrcat(r->pool, "?", r->args, NULL)
: "";
}
so that "%m %U%q %H" == "%r", and the logging module would prepend "?" if
there was data, or log an empty char (i.e., nothing) if no query_string.
-Peter
At 12:39pm Sep 27, 1999, Spidaman The Defenestrator wrote:
> The full request line would have the uri and the query string so having a
> log format that has "%m %U %H" would not replace %r, right?
>
> Meanwhile, back at the ranch...
> > For a recent project, we wanted to customize the log format and realized
> > that while %r refers to the full request line and %U refers to the uri,
> > there was no good way to refer to the method or protocol.
> > %m => r->method (mnemonic: "m" for "method")
> > %H => r->protocol (mnemonic: "H" begins "HTTP/1.0")
Re: [PATCH] mod_log_config: expose r->protocol, r->method
Posted by Spidaman The Defenestrator <sp...@salon.com>.
I mentioned this because I used a similar hack to mod_log_config to munge
some vhost-specific id into a dummy request line for the logs. I ended
doing something gross (though I no longer recall what that was :) to force
the query string in there as well. So if seperate method and protocol
objects are added to mod_log_config, may as well add the query string.
Meanwhile, back at the ranch...
> > The full request line would have the uri and the query string so having a
> > log format that has "%m %U %H" would not replace %r, right?
>
> No. And having them separately is something I recently acutally found
> quite usefull.
--
Salon Internet http://www.salon.com/
HTTP mechanic, Perl diver, Mebwaster, Some of the above
Ian Kallen <id...@salon.com> / AIM: iankallen / Fax: (561) 619-0995
Re: [PATCH] mod_log_config: expose r->protocol, r->method
Posted by Dirk-Willem van Gulik <di...@webweaving.org>.
On Mon, 27 Sep 1999, Spidaman The Defenestrator wrote:
> The full request line would have the uri and the query string so having a
> log format that has "%m %U %H" would not replace %r, right?
No. And having them separately is something I recently acutally found
quite usefull.
Dw
Re: [PATCH] mod_log_config: expose r->protocol, r->method
Posted by Spidaman The Defenestrator <sp...@salon.com>.
The full request line would have the uri and the query string so having a
log format that has "%m %U %H" would not replace %r, right?
Meanwhile, back at the ranch...
> For a recent project, we wanted to customize the log format and realized
> that while %r refers to the full request line and %U refers to the uri,
> there was no good way to refer to the method or protocol. Since the
> request structure already has protocol and method members, I added code to
> src/modules/standard/mod_log_config.c to add % LogFormat shortcuts:
> %m => r->method (mnemonic: "m" for "method")
> %H => r->protocol (mnemonic: "H" begins "HTTP/1.0")
>
> The attached patch is a diff -c against the source for mod_log_config.c in
> the latest CVS tarball
> (http://dev.apache.org/from-cvs/apache-1.3/apache-1.3_19990927131226.tar.gz)
>
> -Peter Watkins
>
> *** mod_log_config.c.cvs19990927131226 Mon Sep 27 10:51:42 1999
> --- mod_log_config.c Mon Sep 27 10:52:02 1999
> ***************
> *** 334,339 ****
> --- 334,347 ----
> {
> return r->uri;
> }
> + static const char *log_request_method(request_rec *r, char *a)
> + {
> + return r->method;
> + }
> + static const char *log_request_protocol(request_rec *r, char *a)
> + {
> + return r->protocol;
> + }
> static const char *log_status(request_rec *r, char *a)
> {
> return pfmt(r->pool, r->status);
> ***************
> *** 505,510 ****
> --- 513,524 ----
> },
> {
> 'P', log_child_pid, 0
> + },
> + {
> + 'H', log_request_protocol, 0
> + },
> + {
> + 'm', log_request_method, 0
> },
> {
> '\0'
>
>
--
Salon Internet http://www.salon.com/
HTTP mechanic, Perl diver, Mebwaster, Some of the above
Ian Kallen <id...@salon.com> / AIM: iankallen / Fax: (561) 619-0995
Re: [PATCH] mod_log_config: expose r->protocol, r->method
Posted by Dirk-Willem van Gulik <di...@webweaving.org>.
On Mon, 27 Sep 1999, Peter W wrote:
> For a recent project, we wanted to customize the log format and realized
> that while %r refers to the full request line and %U refers to the uri,
> there was no good way to refer to the method or protocol. Since the
> request structure already has protocol and method members, I added code to
> src/modules/standard/mod_log_config.c to add % LogFormat shortcuts:
> %m => r->method (mnemonic: "m" for "method")
> %H => r->protocol (mnemonic: "H" begins "HTTP/1.0")
See commit. Let me know if this is correct.
Dw.