summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_http_route.c
diff options
context:
space:
mode:
authorAlejandro Colomar <alx@nginx.com>2023-01-26 15:07:12 +0100
committerAlejandro Colomar <alx@nginx.com>2023-03-21 13:02:38 +0100
commit0ebce31c9287cb97b626d61b62e83681b2864fe8 (patch)
tree83c2841dd2e1a7a9e6f42517fda90b28763b96e3 /src/nxt_http_route.c
parent773c341d70d45a501e6ed4adb0fc6d385423a920 (diff)
downloadunit-0ebce31c9287cb97b626d61b62e83681b2864fe8.tar.gz
unit-0ebce31c9287cb97b626d61b62e83681b2864fe8.tar.bz2
HTTP: added route logging.
- Configuration: added "/config/settings/http/log_route". Type: bool Default: false This adds configurability to the error log. It allows enabling and disabling logs related to how the router performs selection of the routes. - HTTP: logging request line. Log level: [notice] The request line is essential to understand which logs correspond to which request when reading the logs. - HTTP: logging route that's been discarded. Log level: [info] - HTTP: logging route whose action is selected. Log level: [notice] - HTTP: logging when "fallback" action is taken. Log level: [notice] Closes: <https://github.com/nginx/unit/issues/758> Link: <https://github.com/nginx/unit/pull/824> Link: <https://github.com/nginx/unit/pull/839> Suggested-by: Timo Stark <t.stark@nginx.com> Suggested-by: Mark L Wood-Patrick <mwoodpatrick@gmail.com> Suggested-by: Liam Crilly <liam@nginx.com> Tested-by: Liam Crilly <liam@nginx.com> Acked-by: Artem Konev <a.konev@f5.com> Cc: Andrew Clayton <a.clayton@nginx.com> Cc: Andrei Zeliankou <zelenkov@nginx.com> Reviewed-by: Zhidao Hong <z.hong@f5.com> Signed-off-by: Alejandro Colomar <alx@nginx.com>
Diffstat (limited to 'src/nxt_http_route.c')
-rw-r--r--src/nxt_http_route.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/nxt_http_route.c b/src/nxt_http_route.c
index a4dd8f4a..f439c957 100644
--- a/src/nxt_http_route.c
+++ b/src/nxt_http_route.c
@@ -1548,6 +1548,18 @@ nxt_http_route_handler(nxt_task_t *task, nxt_http_request_t *r,
for (i = 0; i < route->items; i++) {
action = nxt_http_route_match(task, r, route->match[i]);
+
+ if (nxt_slow_path(r->log_route)) {
+ uint32_t lvl = (action == NULL) ? NXT_LOG_INFO : NXT_LOG_NOTICE;
+ const char *sel = (action == NULL) ? "discarded" : "selected";
+
+ if (route->name.length == 0) {
+ nxt_log(task, lvl, "\"routes/%z\" %s", i, sel);
+ } else {
+ nxt_log(task, lvl, "\"routes/%V/%z\" %s", &route->name, i, sel);
+ }
+ }
+
if (action != NULL) {
return action;
}