9 #include "connection.h"
18 #define snprintf _snprintf
21 /* the global log descriptors */
26 ** ADDR USER AUTH DATE REQUEST CODE BYTES REFERER AGENT [TIME]
28 ** ADDR = client->con->ip
30 ** we should do this for real once we support authentication
32 ** DATE = _make_date(client->con->con_time)
33 ** REQUEST = build from client->parser
34 ** CODE = client->respcode
35 ** BYTES = client->con->sent_bytes
36 ** REFERER = get from client->parser
37 ** AGENT = get from client->parser
38 ** TIME = timing_get_time() - client->con->con_time
40 void logging_access(client_t
*client
)
51 /* TODO: localtime is not threadsafe on all platforms
52 ** we should probably use localtime_r if it's available
54 PROTECT_CODE(thetime
= localtime(&now
); strftime(datebuf
, 128, LOGGING_FORMAT_CLF
, thetime
))
56 /* build the request */
57 snprintf(reqbuf
, 1024, "%s %s %s/%s", httpp_getvar(client
->parser
, HTTPP_VAR_REQ_TYPE
), httpp_getvar(client
->parser
, HTTPP_VAR_URI
),
58 httpp_getvar(client
->parser
, HTTPP_VAR_PROTOCOL
), httpp_getvar(client
->parser
, HTTPP_VAR_VERSION
));
60 stayed
= now
- client
->con
->con_time
;
62 log_write_direct(accesslog
, "%s - - [%s] \"%s\" %d %lld \"%s\" \"%s\" %d",
67 client
->con
->sent_bytes
,
68 (httpp_getvar(client
->parser
, "referer") != NULL
) ? httpp_getvar(client
->parser
, "referer") : "-",
69 (httpp_getvar(client
->parser
, "user-agent") != NULL
) ? httpp_getvar(client
->parser
, "user-agent") : "-",
75 void restart_logging ()
77 ice_config_t
*config
= config_get_config_unlocked();
79 if (strcmp (config
->error_log
, "-"))
81 char fn_error
[FILENAME_MAX
];
82 snprintf (fn_error
, FILENAME_MAX
, "%s%s%s", config
->log_dir
, PATH_SEPARATOR
, config
->error_log
);
83 log_set_filename (errorlog
, fn_error
);
84 log_set_level (errorlog
, config
->loglevel
);
85 log_reopen (errorlog
);
88 if (strcmp (config
->access_log
, "-"))
90 char fn_error
[FILENAME_MAX
];
91 snprintf (fn_error
, FILENAME_MAX
, "%s%s%s", config
->log_dir
, PATH_SEPARATOR
, config
->access_log
);
92 log_set_filename (accesslog
, fn_error
);
93 log_reopen (accesslog
);