Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apisix/plugins/syslog/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ 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
local ok, err = logger:log(log_message)

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
Expand Down
59 changes: 59 additions & 0 deletions t/plugin/syslog.t
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading