1- -- Copyright (C) 2013-2014 Jiale Zhi (calio), Cloudflare Inc.
1+ -- Copyright (C) 2013-2014 Jiale Zhi (calio), CloudFlare Inc.
22-- require "luacov"
33
44local concat = table.concat
@@ -32,10 +32,10 @@ if not ngx.config or not ngx.config.ngx_lua_version
3232
3333 is_exiting = function () return false end
3434
35- ngx_log (CRIT , " lua-resty-logger-socket working with ngx_lua module < 0.9.3 "
36- .. " has a serious issue that some log messages may be lost when "
37- .. " nginx reloads. We strongly recommend you update your ngx_lua "
38- .. " module to at least 0.9.3" )
35+ ngx_log (CRIT , " We strongly recommend you to update your ngx_lua module to "
36+ .. " 0.9.3 or above. lua-resty-logger-socket will lose some log "
37+ .. " messages when Nginx reloads if it works with ngx_lua module "
38+ .. " below 0.9.3" )
3939else
4040 is_exiting = ngx .worker .exiting
4141end
@@ -59,7 +59,7 @@ local buffer_size = 0
5959local send_buffer = " "
6060-- 1st level buffer, it stores incoming logs
6161local log_buffer_data = new_tab (20000 , 0 )
62- -- number of log lines in current buffer, starts from 0
62+ -- number of log lines in current 1st level buffer, starts from 0
6363local log_buffer_index = 0
6464
6565local last_error
@@ -95,7 +95,7 @@ local function _do_connect()
9595 sock :settimeout (timeout )
9696 end
9797
98- -- host/ port and path config have already been checked in init()
98+ -- " host"/" port" and " path" have already been checked in init()
9999 if host and port then
100100 ok , err = sock :connect (host , port )
101101 elseif path then
@@ -114,9 +114,9 @@ local function _connect()
114114
115115 if connecting then
116116 if debug then
117- ngx_log (DEBUG , " previous connect not finished" )
117+ ngx_log (DEBUG , " previous connection not finished" )
118118 end
119- return nil , " previous connect not finished"
119+ return nil , " previous connection not finished"
120120 end
121121
122122 connected = false
@@ -133,10 +133,10 @@ local function _connect()
133133 end
134134
135135 if debug then
136- ngx_log (DEBUG , " retry to connect to the log server: " , err )
136+ ngx_log (DEBUG , " reconnect to the log server: " , err )
137137 end
138138
139- -- ngx.sleep use seconds to count time
139+ -- ngx.sleep time is in seconds
140140 if not exiting then
141141 ngx_sleep (retry_interval / 1000 )
142142 end
@@ -163,8 +163,8 @@ local function _prepare_stream_buffer()
163163 log_buffer_data = new_tab (20000 , 0 )
164164 counter = 0
165165 if debug then
166- ngx_log (DEBUG , " log buffer max reuse(" .. max_buffer_reuse
167- .. " ) reached, create new log_buffer_data" )
166+ ngx_log (DEBUG , " log buffer reuse limit (" .. max_buffer_reuse
167+ .. " ) reached, create a new \" log_buffer_data\" " )
168168 end
169169 end
170170end
@@ -178,7 +178,7 @@ local function _do_flush()
178178
179179 local bytes , err = sock :send (packet )
180180 if not bytes then
181- -- sock:send always close current connection on error
181+ -- " sock:send" always closes current connection on error
182182 return nil , err
183183 end
184184
206206local function _flush_lock ()
207207 if not flushing then
208208 if debug then
209- ngx_log (DEBUG , " flush lock accquired " )
209+ ngx_log (DEBUG , " flush lock acquired " )
210210 end
211211 flushing = true
212212 return true
@@ -235,7 +235,7 @@ local function _flush()
235235
236236 if not _need_flush () then
237237 if debug then
238- ngx_log (DEBUG , " do not need to flush:" , log_buffer_index )
238+ ngx_log (DEBUG , " no need to flush:" , log_buffer_index )
239239 end
240240 _flush_unlock ()
241241 return true
@@ -260,10 +260,10 @@ local function _flush()
260260 end
261261
262262 if debug then
263- ngx_log (DEBUG , " retry to send log message to the log server: " , err )
263+ ngx_log (DEBUG , " resend log messages to the log server: " , err )
264264 end
265265
266- -- ngx.sleep use seconds to count time
266+ -- ngx.sleep time is in seconds
267267 if not exiting then
268268 ngx_sleep (retry_interval / 1000 )
269269 end
@@ -274,7 +274,7 @@ local function _flush()
274274 _flush_unlock ()
275275
276276 if not bytes then
277- local err_msg = " try to send log message to the log server "
277+ local err_msg = " try to send log messages to the log server "
278278 .. " failed after " .. max_retry_times .. " retries: "
279279 .. err
280280 _write_error (err_msg )
@@ -326,7 +326,7 @@ function _M.init(user_config)
326326 elseif k == " max_retry_times" then
327327 max_retry_times = v
328328 elseif k == " retry_interval" then
329- -- ngx.sleep uses seconds to count sleep time
329+ -- ngx.sleep time is in seconds
330330 retry_interval = v
331331 elseif k == " pool_size" then
332332 pool_size = v
@@ -336,12 +336,13 @@ function _M.init(user_config)
336336 end
337337
338338 if not (host and port ) and not path then
339- return nil , " no logging server configured. Need host/port or path."
339+ return nil , " no logging server configured. \" host\" /\" port\" or "
340+ .. " \" path\" is required."
340341 end
341342
342343
343344 if (flush_limit >= drop_limit ) then
344- return nil , " flush_limit should < drop_limit"
345+ return nil , " \" flush_limit\" should be < \" drop_limit\" "
345346 end
346347
347348 flushing = false
@@ -375,14 +376,14 @@ function _M.log(msg)
375376
376377 local msg_len = # msg
377378
378- -- return result of _flush_buffer is not checked, because it writes
379+ -- response of " _flush_buffer" is not checked, because it writes
379380 -- error buffer
380381 if (is_exiting ()) then
381382 exiting = true
382383 _write_buffer (msg )
383384 _flush_buffer ()
384385 if (debug ) then
385- ngx_log (DEBUG , " worker exiting" )
386+ ngx_log (DEBUG , " Nginx worker is exiting" )
386387 end
387388 bytes = 0
388389 elseif (msg_len + buffer_size < flush_limit ) then
@@ -395,10 +396,11 @@ function _M.log(msg)
395396 else
396397 _flush_buffer ()
397398 if (debug ) then
398- ngx_log (DEBUG , " logger buffer is full, this log would be dropped" )
399+ ngx_log (DEBUG , " logger buffer is full, this log message will be "
400+ .. " dropped" )
399401 end
400402 bytes = 0
401- --- this message does not fit in buffer, drop it
403+ --- this log message doesn't fit in buffer, drop it
402404 end
403405
404406 if last_error then
0 commit comments