Commit 8b1c1867 authored by Dag Erling Smørgrav's avatar Dag Erling Smørgrav

Style and whitespace cleanup + clarify comment explaining the log format


git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@1361 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 3aef964e
...@@ -29,13 +29,23 @@ ...@@ -29,13 +29,23 @@
* *
* $Id$ * $Id$
* *
* Program that will get data from the shared memory log. When it has the data * Obtain log data from the shared memory log, order it by session ID, and
* it will order the data based on the sessionid. When the data is ordered * display it in Apache / NCSA combined log format:
* and session is finished it will write the data into disk. Logging will be
* in NCSA extended/combined access log format.
* *
* "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" * "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""
* *
* where the fields are defined as follows:
*
* %h Client host name or IP address (always the latter)
* %l Client user ID as reported by identd (always "-")
* %u User ID if using HTTP authentication, or "-"
* %t Date and time of request
* %r Request line
* %s Status code
* %b Length of reply body, or "-"
* %{Referer}i Contents of "Referer" request header
* %{User-agent}i Contents of "User-agent" request header
*
* TODO: - Log in any format one wants * TODO: - Log in any format one wants
* - Maybe rotate/compress log * - Maybe rotate/compress log
*/ */
...@@ -57,13 +67,13 @@ ...@@ -57,13 +67,13 @@
#include "varnishapi.h" #include "varnishapi.h"
static struct logline { static struct logline {
char df_h[4 * (3 + 1)]; /* Datafield for %h (IP adress) */ char df_h[4 * (3 + 1)]; /* %h (host name / IP adress)*/
char df_s[4]; /* Datafield for %s, Status */ char df_s[4]; /* %s, Status */
char df_b[12]; /* Datafield for %b, Bytes */ char df_b[12]; /* %b, Bytes */
char *df_R; /* Datafield for %{Referer} */ char *df_R; /* %{Referer}i */
char *df_U; /* Datafield for %{User-agent} */ char *df_U; /* %{User-agent}i */
char *df_RU; /* Datafield for %l, Remote user */ char *df_RU; /* %u, Remote user */
int bogus_req; /* bogus request */ int bogus_req; /* bogus request */
struct vsb *sb; struct vsb *sb;
} *ll[65536]; } *ll[65536];
...@@ -82,7 +92,8 @@ ispfx(const char *ptr, unsigned len, const char *pfx) ...@@ -82,7 +92,8 @@ ispfx(const char *ptr, unsigned len, const char *pfx)
} }
static int static int
extended_log_format(void *priv, unsigned tag, unsigned fd, unsigned len, unsigned spec, const char *ptr) extended_log_format(void *priv, unsigned tag, unsigned fd,
unsigned len, unsigned spec, const char *ptr)
{ {
const char *p; const char *p;
char *q; char *q;
...@@ -164,6 +175,7 @@ extended_log_format(void *priv, unsigned tag, unsigned fd, unsigned len, unsigne ...@@ -164,6 +175,7 @@ extended_log_format(void *priv, unsigned tag, unsigned fd, unsigned len, unsigne
default: default:
break; break;
} }
if (tag != SLT_ReqEnd) if (tag != SLT_ReqEnd)
return (0); return (0);
...@@ -171,13 +183,11 @@ extended_log_format(void *priv, unsigned tag, unsigned fd, unsigned len, unsigne ...@@ -171,13 +183,11 @@ extended_log_format(void *priv, unsigned tag, unsigned fd, unsigned len, unsigne
assert(1 == sscanf(ptr, "%*u %*u.%*u %ld.", &l)); assert(1 == sscanf(ptr, "%*u %*u.%*u %ld.", &l));
t = l; t = l;
localtime_r(&t, &tm); localtime_r(&t, &tm);
strftime(tbuf, sizeof tbuf, "%d/%b/%Y:%T %z", &tm); strftime(tbuf, sizeof tbuf, "%d/%b/%Y:%T %z", &tm);
fprintf(fo, "%s", lp->df_h); fprintf(fo, "%s", lp->df_h);
if (lp->df_RU != NULL){ if (lp->df_RU != NULL) {
base64_init(); base64_init();
lu = sizeof rubuf; lu = sizeof rubuf;
base64_decode(rubuf, lu, lp->df_RU); base64_decode(rubuf, lu, lp->df_RU);
...@@ -188,8 +198,7 @@ extended_log_format(void *priv, unsigned tag, unsigned fd, unsigned len, unsigne ...@@ -188,8 +198,7 @@ extended_log_format(void *priv, unsigned tag, unsigned fd, unsigned len, unsigne
fprintf(fo, " %s", rubuf); fprintf(fo, " %s", rubuf);
free(lp->df_RU); free(lp->df_RU);
lp->df_RU = NULL; lp->df_RU = NULL;
} } else {
else{
fprintf(fo, " -"); fprintf(fo, " -");
} }
fprintf(fo, " - [%s]", tbuf); fprintf(fo, " - [%s]", tbuf);
...@@ -201,17 +210,15 @@ extended_log_format(void *priv, unsigned tag, unsigned fd, unsigned len, unsigne ...@@ -201,17 +210,15 @@ extended_log_format(void *priv, unsigned tag, unsigned fd, unsigned len, unsigne
fprintf(fo, " \"%s\"", lp->df_R); fprintf(fo, " \"%s\"", lp->df_R);
free(lp->df_R); free(lp->df_R);
lp->df_R = NULL; lp->df_R = NULL;
} else {
fprintf(fo, " \"-\"");
} }
else {
fprintf(fo, " \"-\"");
}
if (lp->df_U != NULL) { if (lp->df_U != NULL) {
fprintf(fo, " \"%s\"", lp->df_U); fprintf(fo, " \"%s\"", lp->df_U);
free(lp->df_U); free(lp->df_U);
lp->df_U = NULL; lp->df_U = NULL;
} } else {
else {
fprintf(fo, " \"-\""); fprintf(fo, " \"-\"");
} }
fprintf(fo, "\n"); fprintf(fo, "\n");
...@@ -248,12 +255,13 @@ open_log(const char *ofn, int append) ...@@ -248,12 +255,13 @@ open_log(const char *ofn, int append)
static void static void
usage(void) usage(void)
{ {
fprintf(stderr, "usage: varnishncsa %s [-aV] [-w file]\n", VSL_ARGS); fprintf(stderr, "usage: varnishncsa %s [-aV] [-w file]\n", VSL_ARGS);
exit(1); exit(1);
} }
int int
main(int argc, char **argv) main(int argc, char *argv[])
{ {
int i, c; int i, c;
struct VSL_data *vd; struct VSL_data *vd;
...@@ -311,4 +319,3 @@ main(int argc, char **argv) ...@@ -311,4 +319,3 @@ main(int argc, char **argv)
exit(0); exit(0);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment