MEDIUM: log: Unique ID
The Unique ID, is an ID generated with several informations. You can use
a log-format string to customize it, with the "unique-id-format" keyword,
and insert it in the request header, with the "unique-id-header" keyword.
diff --git a/src/proto_http.c b/src/proto_http.c
index 2f9d3e8..dd2f0d0 100644
--- a/src/proto_http.c
+++ b/src/proto_http.c
@@ -268,6 +268,7 @@
/* memory allocations */
pool2_requri = create_pool("requri", REQURI_LEN, MEM_F_SHARED);
pool2_capture = create_pool("capture", CAPTURE_LEN, MEM_F_SHARED);
+ pool2_uniqueid = create_pool("uniqueid", UNIQUEID_LEN, MEM_F_SHARED);
}
/*
@@ -858,6 +859,7 @@
extern const char *monthname[12];
struct pool_head *pool2_requri;
struct pool_head *pool2_capture;
+struct pool_head *pool2_uniqueid;
/*
* Capture headers from message starting at <som> according to header list
@@ -2397,6 +2399,10 @@
}
}
+ if (!LIST_ISEMPTY(&s->fe->format_unique_id)) {
+ s->unique_id = pool_alloc2(pool2_uniqueid);
+ }
+
/* 4. We may have to convert HTTP/0.9 requests to HTTP/1.0 */
if (unlikely(msg->sl.rq.v_l == 0) && !http_upgrade_v09_to_v10(req, msg, txn))
goto return_bad_req;
@@ -3274,6 +3280,19 @@
get_srv_from_appsession(s, msg->sol + msg->sl.rq.u, msg->sl.rq.u_l);
}
+ /* add unique-id if "header-unique-id" is specified */
+
+ if (!LIST_ISEMPTY(&s->fe->format_unique_id))
+ build_logline(s, s->unique_id, UNIQUEID_LEN, &s->fe->format_unique_id);
+
+ if (s->fe->header_unique_id && s->unique_id) {
+ int ret = snprintf(trash, global.tune.bufsize, "%s: %s", s->fe->header_unique_id, s->unique_id);
+ if (ret < 0 || ret > global.tune.bufsize)
+ goto return_bad_req;
+ if(unlikely(http_header_add_tail(req, &txn->req, &txn->hdr_idx, trash) < 0))
+ goto return_bad_req;
+ }
+
/*
* 9: add X-Forwarded-For if either the frontend or the backend
* asks for it.
@@ -7381,7 +7400,9 @@
pool_free2(pool2_capture, txn->cli_cookie);
pool_free2(pool2_capture, txn->srv_cookie);
pool_free2(apools.sessid, txn->sessid);
+ pool_free2(pool2_uniqueid, s->unique_id);
+ s->unique_id = NULL;
txn->sessid = NULL;
txn->uri = NULL;
txn->srv_cookie = NULL;