Skip to content

Commit

Permalink
log format
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw committed Oct 25, 2023
1 parent 5d92673 commit c206245
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
10 changes: 6 additions & 4 deletions lualib/resty/events/callback.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ function _M:do_event(d)
local now = ngx.now()

if time then
log(DEBUG, "worker-events: receive event; source=", source,
", event=", event, ", wid=", wid, ", time=", now - time)
log(DEBUG, "worker-events [receive]: source=", source,
", event=", event, ", wid=", wid, ", time=", now - time,
", data=", cjson_encode(data))
end

log(DEBUG, "worker-events: handling event; source=", source,
Expand All @@ -139,8 +140,9 @@ function _M:do_event(d)
do_handlerlist(funcs, list, source, event, data, wid)

ngx.update_time()
log(DEBUG, "worker-events: done event; source=", source,
", event=", event, ", wid=", wid, ", time=", ngx.now() - now)
log(DEBUG, "worker-events [done] : source=", source,
", event=", event, ", wid=", wid, ", time=", ngx.now() - now,
", data=", encode(data))

end

Expand Down
13 changes: 8 additions & 5 deletions lualib/resty/events/queue.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local cjson = require "cjson.safe"
local semaphore = require "ngx.semaphore"

local table_new = require "table.new"
Expand Down Expand Up @@ -26,7 +27,7 @@ function _M.new(max_len)
income = 0,
}

ngx.log(ngx.DEBUG, "worker-events: queue init, max_len=", self.max_len)
ngx.log(ngx.DEBUG, "worker-events [queue]: init, max_len=", self.max_len)

return setmetatable(self, _MT)
end
Expand All @@ -37,8 +38,9 @@ function _M:push(item)

local count = last - self.first + 1

ngx.log(ngx.DEBUG, "worker-events: push queue, len=", count,
", income=", self.income, ", outcome=", self.outcome)
ngx.log(ngx.DEBUG, "worker-events [queue]: push , len=", count,
", income=", self.income, ", outcome=", self.outcome,
", data=", cjson_encode(item))

if count >= self.max then
return nil, "queue overflow"
Expand Down Expand Up @@ -76,8 +78,9 @@ function _M:pop()

local count = self.last - self.first + 1

ngx.log(ngx.DEBUG, "worker-events: pop queue, len=", count,
", income=", self.income, ", outcome=", self.outcome)
ngx.log(ngx.DEBUG, "worker-events [queue]: pop , len=", count,
", income=", self.income, ", outcome=", self.outcome,
", data=", cjson_encode(item))

return item
end
Expand Down
2 changes: 1 addition & 1 deletion lualib/resty/events/worker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ function _M:publish(target, source, event, data)
assert(type(source) == "string" and source ~= "", "source is required")
assert(type(event) == "string" and event ~= "", "event is required")

log(DEBUG, "source=", source, ", event=", event, ", data=", cjson_encode(data))
log(DEBUG, "[publish] source=", source, ", event=", event, ", data=", cjson_encode(data))

-- fall back to local events
if self._opts.testing == true then
Expand Down

0 comments on commit c206245

Please sign in to comment.