mirror of
https://github.com/emikulic/darkhttpd.git
synced 2023-08-10 21:13:08 +03:00
Log using Combined Log Format (commonly found in apache log)
Commonly found in Apache log. It adds 2 fields upon the Common Log Format (referer and user-agent). https://en.wikipedia.org/wiki/Common_Log_Format It is just a matter of reordering what your were already logging with a new date formatting. * We are cheating because we always assume HTTP/1.1 as the request header. * We assume the user name is unknown.
This commit is contained in:
parent
85609c8095
commit
d777aacd98
19
darkhttpd.c
19
darkhttpd.c
@ -1280,9 +1280,22 @@ static void logencode(const char *src, char *dest) {
|
|||||||
dest[j] = '\0';
|
dest[j] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Format [when] as a CLF date format, stored in the specified buffer. The same
|
||||||
|
* buffer is returned for convenience.
|
||||||
|
*/
|
||||||
|
#define CLF_DATE_LEN 29 /* strlen("[10/Oct/2000:13:55:36 -0700]")+1 */
|
||||||
|
static char *clf_date(char *dest, const time_t when) {
|
||||||
|
time_t when_copy = when;
|
||||||
|
if (strftime(dest, CLF_DATE_LEN,
|
||||||
|
"[%d/%b/%Y:%H:%M:%S %z]", localtime(&when_copy)) == 0)
|
||||||
|
errx(1, "strftime() failed [%s]", dest);
|
||||||
|
return dest;
|
||||||
|
}
|
||||||
|
|
||||||
/* Add a connection's details to the logfile. */
|
/* Add a connection's details to the logfile. */
|
||||||
static void log_connection(const struct connection *conn) {
|
static void log_connection(const struct connection *conn) {
|
||||||
char *safe_method, *safe_url, *safe_referer, *safe_user_agent;
|
char *safe_method, *safe_url, *safe_referer, *safe_user_agent,
|
||||||
|
dest[CLF_DATE_LEN];
|
||||||
|
|
||||||
if (logfile == NULL)
|
if (logfile == NULL)
|
||||||
return;
|
return;
|
||||||
@ -1307,9 +1320,9 @@ static void log_connection(const struct connection *conn) {
|
|||||||
|
|
||||||
#define use_safe(x) safe_##x ? safe_##x : ""
|
#define use_safe(x) safe_##x ? safe_##x : ""
|
||||||
|
|
||||||
fprintf(logfile, "%lu %s \"%s %s\" %d %llu \"%s\" \"%s\"\n",
|
fprintf(logfile, "%s - - %s \"%s %s HTTP/1.1\" %d %llu \"%s\" \"%s\"\n",
|
||||||
(unsigned long int)now,
|
|
||||||
get_address_text(&conn->client),
|
get_address_text(&conn->client),
|
||||||
|
clf_date(dest, now),
|
||||||
use_safe(method),
|
use_safe(method),
|
||||||
use_safe(url),
|
use_safe(url),
|
||||||
conn->http_code,
|
conn->http_code,
|
||||||
|
Loading…
Reference in New Issue
Block a user