Skip to content

Commit 4bcab1c

Browse files
committed
Now flush() returns 'bytes' and 'err' as described in README
1 parent 11af33a commit 4bcab1c

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

lib/resty/logger/socket.lua

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ local function _do_flush()
197197
return nil, err
198198
end
199199

200-
return true
200+
return bytes
201201
end
202202

203203
local function _need_flush()
@@ -252,14 +252,15 @@ local function _flush()
252252
ngx_log(DEBUG, "start flushing")
253253
end
254254

255+
local bytes
255256
while retry_send <= max_retry_times do
256257
if log_buffer_index > 0 then
257258
_prepare_stream_buffer()
258259
end
259260

260-
ok, err = _do_flush()
261+
bytes, err = _do_flush()
261262

262-
if ok then
263+
if bytes then
263264
break
264265
end
265266

@@ -277,7 +278,7 @@ local function _flush()
277278

278279
_flush_unlock()
279280

280-
if not ok then
281+
if not bytes then
281282
local err_msg = "try to send log message to the log server "
282283
.. "failed after " .. max_retry_times .. " retries: "
283284
.. err
@@ -288,7 +289,7 @@ local function _flush()
288289
buffer_size = buffer_size - #send_buffer
289290
send_buffer = ""
290291

291-
return true
292+
return bytes
292293
end
293294

294295
local function _flush_buffer()

t/flush.t

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ __DATA__
5555
ngx.log(ngx.ERR, err)
5656
end
5757
58-
logger.flush()
59-
ngx.say("ok")
58+
local bytes, err = logger.flush()
59+
ngx.say(bytes)
6060
';
6161
}
6262
--- request
@@ -69,5 +69,5 @@ GET /t?a=1&b=2
6969
--- tcp_query: abcefg
7070
--- tcp_query_len: 6
7171
--- response_body
72-
ok
72+
6
7373

0 commit comments

Comments
 (0)