Commit Diff


commit - fd9a4869253110c96e94b4705d4c3604f4d28ce7
commit + 793835cb26c39202133c754fb33f8909ebf8fb92
blob - 57b7a598ddeea27590c0a34be85654ae6ee30183
blob + 2fbab931b5584fa55d815d53c1cf698ab71fb9bf
--- ChangeLog
+++ ChangeLog
@@ -1,3 +1,7 @@
+2021-02-22  Omar Polo  <op@omarpolo.com>
+
+	* log.c (log_request): add `log on/off' to enable/disable logs per-server or per-location
+
 2021-02-09  Omar Polo  <op@omarpolo.com>
 
 	* parse.y (locopt): add `require client ca' rule to require client certs signed by a specified CA
blob - 2a5b6be551b6d1272f9c77f3e18b6e156faa7f43
blob + 454ddd3c2f24e0fb14a12b84c93856b0e69f748a
--- gmid.h
+++ gmid.h
@@ -66,6 +66,7 @@ struct location {
 	const char	*block_fmt;
 	int		 strip;
 	X509_STORE	*reqca;
+	int		 disable_log;
 };
 
 struct vhost {
@@ -234,6 +235,7 @@ int		 vhost_auto_index(struct vhost*, const char*);
 int		 vhost_block_return(struct vhost*, const char*, int*, const char**);
 int		 vhost_strip(struct vhost*, const char*);
 X509_STORE	*vhost_require_ca(struct vhost*, const char*);
+int		 vhost_disable_log(struct vhost*, const char*);
 void		 mark_nonblock(int);
 void		 loop(struct tls*, int, int);
 
blob - 41fab03a93eb41ec5e8e41deed6da074dc8bdf5d
blob + d61b9940fb62671e6862fa7949041cf0a5a586e6
--- lex.l
+++ lex.l
@@ -65,6 +65,7 @@ ipv6		return TIPV6;
 key		return TKEY;
 lang		return TLANG;
 location	return TLOCATION;
+log		return TLOG;
 mime		return TMIME;
 port		return TPORT;
 prefork		return TPREFORK;
blob - 6bb84f131f85407de99c5dd8ce931ce60aa6ef37
blob + b47444b1be80fa8e5ddde908e6fe880d6a2ed031
--- log.c
+++ log.c
@@ -188,6 +188,9 @@ log_request(struct client *c, char *meta, size_t l)
 	size_t len;
 	int ec;
 
+	if (vhost_disable_log(c->host, c->iri.path))
+		return;
+
 	len = sizeof(c->addr);
 	ec = getnameinfo((struct sockaddr*)&c->addr, len,
 	    hbuf, sizeof(hbuf),
blob - 968670d120f4be2cfeba4e71ef9f90a87843ac3e
blob + 06fdf250bcc88b65db050fde6b1d7e2160329cbb
--- parse.y
+++ parse.y
@@ -58,7 +58,7 @@ void		 advance_loc(void);
 
 %token TIPV6 TPORT TPROTOCOLS TMIME TDEFAULT TTYPE
 %token TCHROOT TUSER TSERVER TPREFORK
-%token TLOCATION TCERT TKEY TROOT TCGI TLANG TINDEX TAUTO
+%token TLOCATION TCERT TKEY TROOT TCGI TLANG TLOG TINDEX TAUTO
 %token TSTRIP TBLOCK TRETURN TENTRYPOINT TREQUIRE TCLIENT TCA
 %token TERR
 
@@ -190,6 +190,7 @@ locopt		: TAUTO TINDEX TBOOL	{ loc->auto_index = $3 ? 
 				yyerror("`lang' specified more than once");
 			loc->lang = $2;
 		}
+		| TLOG TBOOL	{ loc->disable_log = !$2; }
 		| TREQUIRE TCLIENT TCA TSTRING {
 			if (loc->reqca != NULL)
 				yyerror("`require client ca' specified more than once");
blob - 13e0830da7a9235937cd3395010bab9e59143b34
blob + ec0762d8063e547a3c6857f46b5927ba2461e1c7
--- server.c
+++ server.c
@@ -222,6 +222,22 @@ vhost_require_ca(struct vhost *v, const char *path)
 	}
 
 	return v->locations[0].reqca;
+}
+
+int
+vhost_disable_log(struct vhost *v, const char *path)
+{
+	struct location *loc;
+
+	if (v == NULL || path == NULL)
+		return 0;
+
+	for (loc = &v->locations[1]; loc->match != NULL; ++loc) {
+		if (loc->disable_log && matches(loc->match, path))
+				return 1;
+	}
+
+	return v->locations[0].disable_log;
 }
 
 static int