Skip to content

Commit

Permalink
fix the test issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
Akayeshmantha committed Apr 27, 2020
1 parent 203adcd commit 3bcecb6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
11 changes: 4 additions & 7 deletions apisix/plugins/syslog.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
--
local core = require("apisix.core")
local log_util = require("apisix.utils.log-util")
local logger_socket = require "resty.logger.socket"
local logger_socket = require("resty.logger.socket")
local plugin_name = "syslog"
local ngx = ngx

Expand Down Expand Up @@ -49,15 +49,12 @@ function _M.check_schema(conf)
end

function _M.flush_syslog(logger)
if logger.initted() then
local ok, err = logger:flush()
local ok, err = logger:flush(logger)
if not ok then
core.log.error("failed to flush message:", err)
end
end
end


function _M.log(conf)
local entry = log_util.get_full_log(ngx)

Expand All @@ -79,11 +76,11 @@ function _M.log(conf)
tls = conf.tls,
})

if not ok then
if not logger then
core.log.error("failed when initiating the sys logger processor", err)
end

local ok, err = logger.log(core.json.encode(entry))
local ok, err = logger:log(core.json.encode(entry))
if not ok then
core.log.error("failed to log message", err)
end
Expand Down
20 changes: 13 additions & 7 deletions t/plugin/syslog.t
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ done
},
"upstream": {
"nodes": {
"127.0.0.1:1984": 1
"127.0.0.1:1980": 1
},
"type": "roundrobin"
},
Expand All @@ -127,7 +127,7 @@ done
},
"upstream": {
"nodes": {
"127.0.0.1:1984": 1
"127.0.0.1:1980": 1
},
"type": "roundrobin"
},
Expand Down Expand Up @@ -171,13 +171,19 @@ hello world
local plugin = require("apisix.plugins.syslog")
local logger_socket = require "resty.logger.socket"
local logger, err = logger_socket:new({
host = "127.0.0.1",
port = 5044,
flush_limit = 1,
host = "127.0.0.1",
port = 5044,
flush_limit = 100,
})

if not logger then
ngx.log(ngx.ERR, "failed to create logger: ", err)
local bytes, err = logger:log("abc")
if err then
ngx.log(ngx.ERR, err)
end

local bytes, err = logger:log("efg")
if err then
ngx.log(ngx.ERR, err)
end

local ok, err = plugin.flush_syslog(logger)
Expand Down

0 comments on commit 3bcecb6

Please sign in to comment.