[master] e285623 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.
Martin Blix Grydeland
martin at varnish-software.com
Mon Nov 9 15:11:15 CET 2015
commit e285623065145d41512659b3b99c4d6e54a57d78
Author: Kristian Grønfeldt Sørensen <ksorensen at nordija.com>
Date: Mon Dec 15 12:59:17 2014 +0100
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.
diff --git a/bin/varnishncsa/varnishncsa.c b/bin/varnishncsa/varnishncsa.c
index b19b679..f9de015 100644
--- a/bin/varnishncsa/varnishncsa.c
+++ b/bin/varnishncsa/varnishncsa.c
@@ -933,6 +933,28 @@ sighup(void)
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
main(int argc, char * const *argv)
{
@@ -962,6 +984,13 @@ main(int argc, char * const *argv)
format = strdup(optarg);
AN(format);
break;
+ case 'f':
+ /* Format string from file */
+ if (format != NULL)
+ free(format);
+ format = read_format(optarg);
+ AN(format);
+ break;
case 'h':
/* Usage help */
usage(0);
diff --git a/bin/varnishncsa/varnishncsa_options.h b/bin/varnishncsa/varnishncsa_options.h
index 291a1c7..24567c2 100644
--- a/bin/varnishncsa/varnishncsa_options.h
+++ b/bin/varnishncsa/varnishncsa_options.h
@@ -40,6 +40,14 @@
"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 \
VOPT("g:", "[-g <request|vxid>]", "Grouping mode (default: vxid)", \
"The grouping of the log records. The default is to group" \
@@ -60,6 +68,7 @@ VSL_OPT_C
VUT_OPT_d
VUT_OPT_D
NCSA_OPT_F
+NCSA_OPT_f
NCSA_OPT_g
VUT_OPT_h
VUT_OPT_n
More information about the varnish-commit
mailing list