Commit e2856230 authored by Kristian Grønfeldt Sørensen's avatar Kristian Grønfeldt Sørensen Committed by Martin Blix Grydeland

Allow varnishncsa logformat to be read from a file. Adds supports to

varnishncsa for specifying the logging format by reading the log
format from a file using the option "-f". Since -f means prefer
X-Forwarded-For over client.ip in Varnish 3, maybe we should use
another option letter.
parent d1fdd6b4
...@@ -933,6 +933,28 @@ sighup(void) ...@@ -933,6 +933,28 @@ sighup(void)
return (1); return (1);
} }
static char *
read_format(const char *formatfile)
{
FILE *fmtfile;
size_t len = 0;
char *fmt = NULL;
fmtfile = fopen(formatfile, "r");
if (fmtfile == NULL)
VUT_Error(1, "Can't open format file (%s)", strerror(errno));
if (getline(&fmt, &len, fmtfile) == -1) {
free(fmt);
if (feof(fmtfile))
VUT_Error(1, "Empty format file");
else
VUT_Error(1, "Can't read format from file (%s)",
strerror(errno));
}
fclose(fmtfile);
return (fmt);
}
int int
main(int argc, char * const *argv) main(int argc, char * const *argv)
{ {
...@@ -962,6 +984,13 @@ main(int argc, char * const *argv) ...@@ -962,6 +984,13 @@ main(int argc, char * const *argv)
format = strdup(optarg); format = strdup(optarg);
AN(format); AN(format);
break; break;
case 'f':
/* Format string from file */
if (format != NULL)
free(format);
format = read_format(optarg);
AN(format);
break;
case 'h': case 'h':
/* Usage help */ /* Usage help */
usage(0); usage(0);
......
...@@ -40,6 +40,14 @@ ...@@ -40,6 +40,14 @@
"Set the output log format string." \ "Set the output log format string." \
) )
#define NCSA_OPT_f \
VOPT("f:", "[-f formatfile]", "Read output format from file", \
"Read output format from a file. Will read a single line" \
" from the specified file, and use that line as the" \
" format." \
)
#define NCSA_OPT_g \ #define NCSA_OPT_g \
VOPT("g:", "[-g <request|vxid>]", "Grouping mode (default: vxid)", \ VOPT("g:", "[-g <request|vxid>]", "Grouping mode (default: vxid)", \
"The grouping of the log records. The default is to group" \ "The grouping of the log records. The default is to group" \
...@@ -60,6 +68,7 @@ VSL_OPT_C ...@@ -60,6 +68,7 @@ VSL_OPT_C
VUT_OPT_d VUT_OPT_d
VUT_OPT_D VUT_OPT_D
NCSA_OPT_F NCSA_OPT_F
NCSA_OPT_f
NCSA_OPT_g NCSA_OPT_g
VUT_OPT_h VUT_OPT_h
VUT_OPT_n VUT_OPT_n
......
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