日志收集,我是严格按照文档上来的,但是当openresty lua_code_cache on的时候 日志无法推送到rsyslog,如果为off ,则一切正常
https://moonbingbing.gitbooks.io/openresty-best-practices/ngx_lua/log.html
这段代码一定是写在log阶段的,请大神帮忙看看什么原因呢?
openresty 1.11 和1.13 都是这样子的。
local logger = require "./resty.socket"
local json = require "cjson"
if not logger.initted() then
local ok, err = logger.init{
host = '127.0.0.1',
port = 514,
flush_limit = 1,
drop_limit = 5000,
-- periodic_flush = 1,
}
if not ok then
ngx.log(ngx.ERR, "failed to initialize the logger: ", err)
return
end
local querys = ngx.req.get_uri_args()
local data = {
name=111,
name2="name2",
query=querys
}
local json = json.encode(data)
ngx.log(ngx.DEBUG, #json, 'rsyslog-json length')
local bytes, err = logger.log(json)
ngx.log(ngx.DEBUG, json, 'rsyslog-json')
ngx.log(ngx.DEBUG, bytes, 'bytesbytes')
if err then
ngx.log(ngx.ERR, "failed to log message: ", err)
end
end