Hello!
On Tue, Oct 28, 2014 at 6:56 AM, Pradeep L wrote:
> I tried to log the response body using this
>
> body_filter_by_lua 'print(ngx.arg[1]' ;
>
> the response body is being logged to error.log file .
>
> Is there a way to log the response to a different file other than access.log
> or error.log ?
>
You can implement this yourself in a custom Lua module doing file I/O
directly. Some caveats though:
1. You'd better cache the file descriptor to save the open and close syscalls.
2. You'd better use LuaJIT FFI (or something like that) to access the
libc wrapper for the write() syscall directly to prevent libc's own
buffering from causing issues when multiple workers writing to the
same file,
3. It might be tricky to honor nginx's USR1 signal for reopening the
log files. Let me know what you need on the ngx_lua side if you really
need this.
Seems like this library can be called lua-resty-logger :)
BTW, we already have a lua-resty-logger-socket library that logs to
socket-based syslog services:
https://github.com/cloudflare/lua-resty-logger-socket
Unlike file based logging, this is 100% nonblocking :)
Regards,
-agentzh