This is interesting, thanks
On Tue, May 17, 2016, at 13:55, 'Josh Enders' via openresty-en wrote:
On Monday, May 16, 2016 at 12:54:28 AM UTC-7, Toni Su wrote:
Hi,
is there any to write access log with lua api?
1. First initialize a named Unix socket. Here we're using to listen on
sudo -u nobody sh -c 'socat - unix-listen:/tmp/resty.sock,fork
2. With we can establish a connection to the Unix socket for the nginx workers:
http {
init_by_lua_file conf/init.lua;
}
3. Contents of
logger = require "resty.logger.socket"
if not logger.initted() then
local ok, err = logger.init {
path = '/tmp/resty.sock',
}
if not ok then
ngx.log(ngx.ERR, "Failed to initialize the logger: ", err)
end
end
4. Within you can log messages with:
local message = "Hello from OpenResty"
local bytes, err = logger.log(message)
if err then
ngx.log(ngx.ERR, "Failed to log message.", err)
return ngx.exit(ngx.HTTP_SERVICE_UNAVAILABLE)
end
--
.