Skip to content

Commit

Permalink
alter to use the new sys logger version.
Browse files Browse the repository at this point in the history
  • Loading branch information
Akayeshmantha committed Apr 27, 2020
1 parent 641c95e commit 203adcd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 23 deletions.
37 changes: 18 additions & 19 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 = require("resty.logger.socket")
local logger_socket = require "resty.logger.socket"
local plugin_name = "syslog"
local ngx = ngx

Expand Down Expand Up @@ -48,9 +48,9 @@ function _M.check_schema(conf)
return core.schema.check(schema, conf)
end

function _M.flush_syslog()
function _M.flush_syslog(logger)
if logger.initted() then
local ok, err = logger.flush()
local ok, err = logger:flush()
if not ok then
core.log.error("failed to flush message:", err)
end
Expand All @@ -66,22 +66,21 @@ function _M.log(conf)
return
end

if not logger.initted() then
local ok, err = logger.init{
host = conf.host,
port = conf.port,
flush_limit = conf.flush_limit,
drop_limit = conf.drop_limit,
timeout = conf.timeout,
sock_type = conf.sock_type,
max_retry_times = conf.max_retry_times,
retry_interval = conf.retry_interval,
pool_size = conf.pool_size,
tls = conf.tls,
}
if not ok then
core.log.error("failed when initiating the sys logger processor", err)
end
local logger, err = logger_socket:new({
host = conf.host,
port = conf.port,
flush_limit = conf.flush_limit,
drop_limit = conf.drop_limit,
timeout = conf.timeout,
sock_type = conf.sock_type,
max_retry_times = conf.max_retry_times,
retry_interval = conf.retry_interval,
pool_size = conf.pool_size,
tls = conf.tls,
})

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

local ok, err = logger.log(core.json.encode(entry))
Expand Down
2 changes: 1 addition & 1 deletion rockspec/apisix-master-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ dependencies = {
"jsonschema = 0.8",
"lua-resty-ipmatcher = 0.6",
"lua-resty-kafka = 0.07",
"lua-resty-logger-socket = 1.0-0",
"lua-resty-logger-socket = 2.0-0",
}

build = {
Expand Down
17 changes: 14 additions & 3 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:1980": 1
"127.0.0.1:1984": 1
},
"type": "roundrobin"
},
Expand All @@ -127,7 +127,7 @@ done
},
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
"127.0.0.1:1984": 1
},
"type": "roundrobin"
},
Expand Down Expand Up @@ -169,7 +169,18 @@ hello world
location /t {
content_by_lua_block {
local plugin = require("apisix.plugins.syslog")
local ok, err = plugin.flush_syslog()
local logger_socket = require "resty.logger.socket"
local logger, err = logger_socket:new({
host = "127.0.0.1",
port = 5044,
flush_limit = 1,
})

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

local ok, err = plugin.flush_syslog(logger)
if not ok then
ngx.say(err)
end
Expand Down

0 comments on commit 203adcd

Please sign in to comment.