Skip to content

Commit 0034317

Browse files
author
Akayeshmantha
committed
fix the test issues.
1 parent 8f55633 commit 0034317

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

apisix/plugins/syslog.lua

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
--
1717
local core = require("apisix.core")
1818
local log_util = require("apisix.utils.log-util")
19-
local logger_socket = require "resty.logger.socket"
19+
local logger_socket = require("resty.logger.socket")
2020
local plugin_name = "syslog"
2121
local ngx = ngx
2222

@@ -49,15 +49,12 @@ function _M.check_schema(conf)
4949
end
5050

5151
function _M.flush_syslog(logger)
52-
if logger.initted() then
53-
local ok, err = logger:flush()
52+
local ok, err = logger:flush(logger)
5453
if not ok then
5554
core.log.error("failed to flush message:", err)
5655
end
57-
end
5856
end
5957

60-
6158
function _M.log(conf)
6259
local entry = log_util.get_full_log(ngx)
6360

@@ -79,11 +76,11 @@ function _M.log(conf)
7976
tls = conf.tls,
8077
})
8178

82-
if not ok then
79+
if not logger then
8380
core.log.error("failed when initiating the sys logger processor", err)
8481
end
8582

86-
local ok, err = logger.log(core.json.encode(entry))
83+
local ok, err = logger:log(core.json.encode(entry))
8784
if not ok then
8885
core.log.error("failed to log message", err)
8986
end

t/plugin/syslog.t

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ done
110110
},
111111
"upstream": {
112112
"nodes": {
113-
"127.0.0.1:1984": 1
113+
"127.0.0.1:1980": 1
114114
},
115115
"type": "roundrobin"
116116
},
@@ -127,7 +127,7 @@ done
127127
},
128128
"upstream": {
129129
"nodes": {
130-
"127.0.0.1:1984": 1
130+
"127.0.0.1:1980": 1
131131
},
132132
"type": "roundrobin"
133133
},
@@ -171,13 +171,19 @@ hello world
171171
local plugin = require("apisix.plugins.syslog")
172172
local logger_socket = require "resty.logger.socket"
173173
local logger, err = logger_socket:new({
174-
host = "127.0.0.1",
175-
port = 5044,
176-
flush_limit = 1,
174+
host = "127.0.0.1",
175+
port = 5044,
176+
flush_limit = 100,
177177
})
178178

179-
if not logger then
180-
ngx.log(ngx.ERR, "failed to create logger: ", err)
179+
local bytes, err = logger:log("abc")
180+
if err then
181+
ngx.log(ngx.ERR, err)
182+
end
183+
184+
local bytes, err = logger:log("efg")
185+
if err then
186+
ngx.log(ngx.ERR, err)
181187
end
182188

183189
local ok, err = plugin.flush_syslog(logger)

0 commit comments

Comments
 (0)