On Thu, May 17, 2012 at 5:06 AM, Matthieu Tourne
<matthie...@gmail.com> wrote:
> I modified a bit the logging, so it adds a '[Lua]' prefix, the name of the
> file, line number and name of the function who called ngx.log. (well
> sometimes, you get the parent function if it's a Lua tail call)
>
> Just wanted to ask how you felt about that, or maybe I can introduce a
> ngx.vlog() for verbose log ?
>
> It produces log lines like this :
>
> 012/05/16 13:48:08 [debug] 21980#0: *1 [Lua] <request_body.lua:23>
> read_body(): total_size: 8366
>
> Here is the diff, for reference :
>
> diff --git a/src/ngx_http_lua_log.c b/src/ngx_http_lua_log.c
> index ed26636..0551a8f 100644
> --- a/src/ngx_http_lua_log.c
> +++ b/src/ngx_http_lua_log.c
> @@ -27,6 +27,7 @@ int
> ngx_http_lua_ngx_log(lua_State *L)
> {
> ngx_http_request_t *r;
> + lua_Debug ar;
>
> lua_getglobal(L, GLOBALS_SYMBOL_REQUEST);
> r = lua_touserdata(L, -1);
> @@ -38,7 +39,21 @@ ngx_http_lua_ngx_log(lua_State *L)
> /* remove log-level param from stack */
> lua_remove(L, 1);
>
> - return log_wrapper(r, "", (ngx_uint_t) level, L);
> + /* Add debug info */
> + lua_getstack(L, 1, &ar);
> + lua_getinfo(L, "Snl", &ar);
> + lua_pushfstring(L, "<%s:%d>",
> + basename(ar.short_src),
> + ar.currentline ? ar.currentline : ar.linedefined);
> + lua_insert(L, 1);
> + if (*ar.namewhat != '\0' && *ar.what == 'L') {
> + lua_pushfstring(L, " %s(): ", ar.name);
> + } else {
> + lua_pushliteral(L, ": ");
> + }
> + lua_insert(L, 2);
> +
> + return log_wrapper(r, "[Lua] ", (ngx_uint_t) level, L);
> }
>
> dd("(lua-log) can't output log due to invalid logging context!");
>
>
I've committed a modified version of your patch to the "logging" branch:
https://github.com/chaoslawful/lua-nginx-module/commit/f75f20d1
I've made the debug info also available for print() and I'm using a
more concise format, as in
[error] ... test.lua:6: bar(): ...
Also added some tests for various cases to t/009-log.t, as you can see
in the commit mentioned above.
Regards,
-agentzh
P.S. I'm cc'ing the openresty mailing list:
https://groups.google.com/group/openresty