From b954547c724daa40d353c503c330cbeadb53078c Mon Sep 17 00:00:00 2001 From: Piotr Przybylski Date: Mon, 9 Sep 2024 20:26:18 +0200 Subject: [PATCH] Make connection pool name logging optional --- README.md | 1 + lib/resty/http_connect.lua | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 59c02f5a..95c16c65 100644 --- a/README.md +++ b/README.md @@ -170,6 +170,7 @@ The options table has the following fields: * `host`: target host, or path to a unix domain socket * `port`: port on target host, will default to `80` or `443` based on the scheme * `pool`: custom connection pool name. Option as per [OpenResty docs](https://github.com/openresty/lua-nginx-module#tcpsockconnect), except that the default will become a pool name constructed using the SSL / proxy properties, which is important for safe connection reuse. When in doubt, leave it blank! +* `pool_debug`: set to `true` to log the connection pool name at `DEBUG` level, off by default * `pool_size`: option as per [OpenResty docs](https://github.com/openresty/lua-nginx-module#tcpsockconnect) * `backlog`: option as per [OpenResty docs](https://github.com/openresty/lua-nginx-module#tcpsockconnect) * `proxy_opts`: sub-table, defaults to the global proxy options set, see [set\_proxy\_options](#set_proxy_options). diff --git a/lib/resty/http_connect.lua b/lib/resty/http_connect.lua index 83b6d2f4..073ab24e 100644 --- a/lib/resty/http_connect.lua +++ b/lib/resty/http_connect.lua @@ -38,6 +38,7 @@ client:connect { host = "myhost.com", -- target machine, or a unix domain socket port = nil, -- port on target machine, will default to 80/443 based on scheme pool = nil, -- connection pool name, leave blank! this function knows best! + pool_debug = nil, -- set to 'true' to log the connection pool name at DEBUG level pool_size = nil, -- options as per: https://github.com/openresty/lua-nginx-module#tcpsockconnect backlog = nil, @@ -250,7 +251,9 @@ local function connect(self, options) -- with a plain http request the authorization is part of the actual request. end - ngx_log(ngx_DEBUG, "poolname: ", poolname) + if options.pool_debug == true then + ngx_log(ngx_DEBUG, "poolname: ", poolname) + end -- do TCP level connection local tcp_opts = { pool = poolname, pool_size = pool_size, backlog = backlog }