diff --git a/apisix/plugins/syslog/init.lua b/apisix/plugins/syslog/init.lua index 15f1eb2b68ab..d80307cc0a63 100644 --- a/apisix/plugins/syslog/init.lua +++ b/apisix/plugins/syslog/init.lua @@ -64,7 +64,7 @@ local function send_syslog_data(conf, log_message, api_ctx) if not logger then res = false - err_msg = "failed when initiating the sys logger processor".. err + err_msg = "failed when initiating the sys logger processor: " .. err end -- reuse the logger object @@ -72,7 +72,7 @@ local function send_syslog_data(conf, log_message, api_ctx) if not ok then res = false - err_msg = "failed to log message" .. err + err_msg = "failed to log message: " .. err end return res, err_msg diff --git a/t/plugin/syslog.t b/t/plugin/syslog.t index e8268fe8b85b..f06318d5a44f 100644 --- a/t/plugin/syslog.t +++ b/t/plugin/syslog.t @@ -687,3 +687,62 @@ GET /t GET /t --- error_log "body":"hello world\n" + + + +=== TEST 22: add plugin with a logger that fails to send the log +--- extra_init_by_lua + local logger_socket = require("resty.logger.socket") + logger_socket.new = function() + return { + log = function() + return nil, "mocked send failure" + end + } + end +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + t('/apisix/admin/plugin_metadata/syslog', ngx.HTTP_DELETE) + local code, body = t('/apisix/admin/routes/1', + ngx.HTTP_PUT, + [[{ + "plugins": { + "syslog": { + "batch_max_size": 1, + "flush_limit": 1, + "host" : "127.0.0.1", + "port" : 5140 + } + }, + "upstream": { + "nodes": { + "127.0.0.1:1980": 1 + }, + "type": "roundrobin" + }, + "uri": "/hello" + }]] + ) + if code >= 300 then + ngx.status = code + end + ngx.say(body) + } + } +--- request +GET /t +--- response_body +passed + + + +=== TEST 23: hit route, send failure is reported with a separator before the cause +--- request +GET /hello +--- response_body +hello world +--- wait: 0.5 +--- error_log +failed to log message: mocked send failure