-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod_log_millisecond.c
55 lines (47 loc) · 1.83 KB
/
mod_log_millisecond.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
** mod_log_millisecond.c -- Apache sample log_millisecond module
** [Autogenerated via ``apxs -n log_millisecond -g'']
**
** To play with this sample module first compile it into a
** DSO file and install it into Apache's modules directory
** by running:
**
** $ apxs -c -i mod_log_millisecond.c
**
** # httpd.conf
** LoadModule log_millisecond_module modules/mod_log_millisecond.so
*/
#include "httpd.h"
#include "http_config.h"
#include "http_protocol.h"
#include "ap_config.h"
#include "apr_strings.h"
#include "mod_log_config.h"
static const char *log_request_duration_milliseconds(request_rec *r, char *a)
{
apr_time_t duration = apr_time_now() - r->request_time;
return apr_psprintf(r->pool, "%" APR_TIME_T_FMT ".%" APR_TIME_T_FMT, apr_time_sec(duration), apr_time_msec(duration));
}
static int log_millisecond_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp)
{
static APR_OPTIONAL_FN_TYPE(ap_register_log_handler) *log_register;
log_register = APR_RETRIEVE_OPTIONAL_FN(ap_register_log_handler);
if (!log_register)
return DECLINED;
log_register(p, "M", log_request_duration_milliseconds, 1);
return OK;
}
static void log_millisecond_register_hooks(apr_pool_t *p)
{
ap_hook_pre_config(log_millisecond_pre_config, NULL, NULL, APR_HOOK_LAST);
}
/* Dispatch list for API hooks */
module AP_MODULE_DECLARE_DATA log_millisecond_module = {
STANDARD20_MODULE_STUFF,
NULL, /* create per-dir config structures */
NULL, /* merge per-dir config structures */
NULL, /* create per-server config structures */
NULL, /* merge per-server config structures */
NULL, /* table of config file commands */
log_millisecond_register_hooks /* register hooks */
};