-.\" $OpenBSD: httpd.conf.5,v 1.17 2014/08/02 21:21:47 doug Exp $
+.\" $OpenBSD: httpd.conf.5,v 1.18 2014/08/03 10:26:43 reyk Exp $
.\"
.\" Copyright (c) 2014 Reyk Floeter <reyk@openbsd.org>
.\"
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: August 2 2014 $
+.Dd $Mdocdate: August 3 2014 $
.Dt HTTPD.CONF 5
.Os
.Sh NAME
The
.Ar style
can be
-.Ar common
+.Ar common ,
+.Ar combined
or
-.Ar combined .
-It is similar to the default Apache and nginx access log.
+.Ar connection .
+The styles
+.Ar common
+and
+.Ar combined
+write a log entry after each request similar to the standard Apache
+and nginx access log formats.
+The style
+.Ar connection
+writes a summarized log entry after each connection,
+that can have multiple requests,
+similar to the format that is used by
+.Xr relayd 8 .
If not specified, the default is
.Ar common .
.It Ic root Ar directory
-/* $OpenBSD: httpd.h,v 1.33 2014/08/02 21:21:47 doug Exp $ */
+/* $OpenBSD: httpd.h,v 1.34 2014/08/03 10:26:43 reyk Exp $ */
/*
* Copyright (c) 2006 - 2014 Reyk Floeter <reyk@openbsd.org>
enum log_format {
LOG_FORMAT_COMMON,
- LOG_FORMAT_COMBINED
+ LOG_FORMAT_COMBINED,
+ LOG_FORMAT_CONNECTION
};
struct server_config {
void server_write(struct bufferevent *, void *);
void server_read(struct bufferevent *, void *);
void server_error(struct bufferevent *, short, void *);
-void server_log(struct client *);
+void server_log(struct client *, const char *);
void server_close(struct client *, const char *);
void server_dump(struct client *, const void *, size_t);
int server_client_cmp(struct client *, struct client *);
-/* $OpenBSD: parse.y,v 1.16 2014/08/02 21:21:47 doug Exp $ */
+/* $OpenBSD: parse.y,v 1.17 2014/08/03 10:26:43 reyk Exp $ */
/*
* Copyright (c) 2007 - 2014 Reyk Floeter <reyk@openbsd.org>
%}
-%token AUTO DIRECTORY FCGI INDEX LISTEN LOCATION LOG NO ON PORT
-%token PREFORK ROOT SERVER SOCKET TYPES
-%token ERROR INCLUDE COMMON COMBINED
+%token AUTO COMMON COMBINED CONNECTION DIRECTORY FCGI INDEX LISTEN LOCATION
+%token LOG NO ON PORT PREFORK ROOT SERVER SOCKET TYPES
+%token ERROR INCLUDE
%token <v.string> STRING
%token <v.number> NUMBER
%type <v.port> port
srv->srv_conf.flags |= SRVFLAG_LOG;
srv->srv_conf.logformat = LOG_FORMAT_COMBINED;
}
+ | LOG CONNECTION {
+ srv->srv_conf.flags &= ~SRVFLAG_NO_LOG;
+ srv->srv_conf.flags |= SRVFLAG_LOG;
+ srv->srv_conf.logformat = LOG_FORMAT_CONNECTION;
+ }
| NO LOG {
srv->srv_conf.flags &= ~SRVFLAG_LOG;
srv->srv_conf.flags |= SRVFLAG_NO_LOG;
{ "auto", AUTO },
{ "combined", COMBINED },
{ "common", COMMON },
+ { "connection", CONNECTION },
{ "directory", DIRECTORY },
{ "fastcgi", FCGI },
{ "include", INCLUDE },
-/* $OpenBSD: server.c,v 1.22 2014/08/02 11:52:01 reyk Exp $ */
+/* $OpenBSD: server.c,v 1.23 2014/08/03 10:26:44 reyk Exp $ */
/*
* Copyright (c) 2006 - 2014 Reyk Floeter <reyk@openbsd.org>
}
void
-server_log(struct client *clt)
+server_log(struct client *clt, const char *msg)
{
- char *ptr = NULL;
+ char ibuf[MAXHOSTNAMELEN], obuf[MAXHOSTNAMELEN];
+ struct server_config *srv_conf = clt->clt_srv_conf;
+ char *ptr = NULL;
+ void (*log_cb)(const char *, ...) = NULL;
+ extern int debug;
- if (!EVBUFFER_LENGTH(clt->clt_log))
- return;
+ switch (srv_conf->logformat) {
+ case LOG_FORMAT_CONNECTION:
+ log_cb = log_info;
+ break;
+ default:
+ if (debug)
+ log_cb = log_debug;
+ if (EVBUFFER_LENGTH(clt->clt_log)) {
+ while ((ptr =
+ evbuffer_readline(clt->clt_log)) != NULL) {
+ log_info("%s", ptr);
+ free(ptr);
+ }
+ }
+ break;
+ }
- while ((ptr = evbuffer_readline(clt->clt_log)) != NULL) {
- log_info("%s", ptr);
- free(ptr);
+ if (log_cb != NULL && msg != NULL) {
+ memset(&ibuf, 0, sizeof(ibuf));
+ memset(&obuf, 0, sizeof(obuf));
+ (void)print_host(&clt->clt_ss, ibuf, sizeof(ibuf));
+ (void)server_http_host(&clt->clt_srv_ss, obuf, sizeof(obuf));
+ if (EVBUFFER_LENGTH(clt->clt_log) &&
+ evbuffer_add_printf(clt->clt_log, "\n") != -1)
+ ptr = evbuffer_readline(clt->clt_log);
+ log_cb("server %s, "
+ "client %d (%d active), %s:%u -> %s, "
+ "%s%s%s", srv_conf->name, clt->clt_id, server_clients,
+ ibuf, ntohs(clt->clt_port), obuf, msg,
+ ptr == NULL ? "" : ",", ptr == NULL ? "" : ptr);
+ if (ptr != NULL)
+ free(ptr);
}
}
void
server_close(struct client *clt, const char *msg)
{
- char ibuf[MAXHOSTNAMELEN], obuf[MAXHOSTNAMELEN];
struct server *srv = clt->clt_srv;
- struct server_config *srv_conf = clt->clt_srv_conf;
- extern int debug;
SPLAY_REMOVE(client_tree, &srv->srv_clients, clt);
if (clt->clt_srvbev != NULL)
bufferevent_disable(clt->clt_srvbev, EV_READ|EV_WRITE);
- server_log(clt);
-
- if (debug && msg != NULL) {
- memset(&ibuf, 0, sizeof(ibuf));
- memset(&obuf, 0, sizeof(obuf));
- (void)print_host(&clt->clt_ss, ibuf, sizeof(ibuf));
- (void)server_http_host(&clt->clt_srv_ss, obuf, sizeof(obuf));
- log_debug("server %s, "
- "client %d (%d active), %s:%u -> %s, "
- "%s", srv_conf->name, clt->clt_id, server_clients,
- ibuf, ntohs(clt->clt_port), obuf, msg);
- }
+ server_log(clt, msg);
if (clt->clt_bev != NULL)
bufferevent_free(clt->clt_bev);
-/* $OpenBSD: server_http.c,v 1.29 2014/08/03 10:22:30 reyk Exp $ */
+/* $OpenBSD: server_http.c,v 1.30 2014/08/03 10:26:44 reyk Exp $ */
/*
* Copyright (c) 2006 - 2014 Reyk Floeter <reyk@openbsd.org>
clt->clt_bev->readcb = server_read_http;
clt->clt_srv_conf = &srv->srv_conf;
- server_log(clt);
+ server_log(clt, NULL);
}
void
if (strftime(tstamp, sizeof(tstamp), "%d/%b/%Y:%H:%M:%S %z", tm) == 0)
return (-1);
- print_host(&clt->clt_ss, ip, sizeof(ip));
+ if (print_host(&clt->clt_ss, ip, sizeof(ip)) == NULL)
+ return (-1);
/*
* For details on common log format, see:
agent == NULL ? "" : agent->kv_value) == -1)
return (-1);
break;
+
+ case LOG_FORMAT_CONNECTION:
+ if (evbuffer_add_printf(clt->clt_log, " [%s]",
+ desc->http_path == NULL ? "" : desc->http_path) == -1)
+ return (-1);
+ break;
}
return (0);