2 * Copyright (c) 2004-2005 Sergey Lyubka <valenok@gmail.com>
5 * "THE BEER-WARE LICENSE" (Revision 42):
6 * Sergey Lyubka wrote this file. As long as you retain this notice you
7 * can do whatever you want with this stuff. If we meet some day, and you think
8 * this stuff is worth it, you can buy me a beer in return.
17 elog(int flags, struct conn *c, const char *fmt, ...)
19 char date[64], buf[URI_MAX];
21 FILE *fp = c == NULL ? NULL : c->ctx->error_log;
25 if (c == NULL || !IS_TRUE(c->ctx, OPT_INETD)) {
27 (void) vfprintf(stderr, fmt, ap);
28 (void) fputc('\n', stderr);
32 strftime(date, sizeof(date), "%a %b %d %H:%M:%S %Y",
33 localtime(¤t_time));
35 len = my_snprintf(buf, sizeof(buf),
36 "[%s] [error] [client %s] \"%s\" ",
37 date, c ? inet_ntoa(c->sa.u.sin.sin_addr) : "-",
38 c && c->request ? c->request : "-");
41 (void) vsnprintf(buf + len, sizeof(buf) - len, fmt, ap);
44 buf[sizeof(buf) - 1] = '\0';
46 if (fp != NULL && (flags & (E_FATAL | E_LOG))) {
47 (void) fprintf(fp, "%s\n", buf);
56 log_access(FILE *fp, const struct conn *c)
58 static const struct vec dash = {"-", 1};
60 const struct vec *user = &c->ch.user.v_vec;
61 const struct vec *referer = &c->ch.referer.v_vec;
62 const struct vec *user_agent = &c->ch.useragent.v_vec;
63 char date[64], buf[URI_MAX], *q1 = "\"", *q2 = "\"";
68 if (referer->len == 0) {
73 if (user_agent->len == 0) {
78 (void) strftime(date, sizeof(date), "%d/%b/%Y:%H:%M:%S",
79 localtime(&c->birth_time));
81 (void) my_snprintf(buf, sizeof(buf),
82 "%s - %.*s [%s %+05d] \"%s\" %d %lu %s%.*s%s %s%.*s%s",
83 inet_ntoa(c->sa.u.sin.sin_addr), user->len, user->ptr,
84 date, tz_offset, c->request ? c->request : "-",
85 c->status, (unsigned long) c->loc.io.total,
86 q1, referer->len, referer->ptr, q1,
87 q2, user_agent->len, user_agent->ptr, q2);
90 (void) fprintf(fp, "%s\n", buf);