ngx_lua log调试

Posted by wxianfeng Tue, 10 Sep 2013 02:46:00 GMT

ngx_lua 如何调试, 查看出错信息,和让修改的lua代码不重启nginx生效?
我在用 ngx_lua + lua-resty-mysql 提供json API, 每次改sql, 都需要 reload nginx , 非常麻烦. 解决办法如下:

打印输出log

可以使用 inspect.lua, 这样 print 就可以打印 lua 的 table 了, table 内的值也可以全部打印出来

local inspect = require "inspect"
local a = { retCode =  1 }
print(inspect(a))

查看输出 或者错误

查看 nginx error.log 即可以看到 print 输出, 或者出错的信息, 注意配置 error_log 指令的时候, 添加上 debug

error_log logs/error.log debug;

lua 代码修改后生效

使用 lua_code_cache off 即可, 另外注意只有使用 content_by_lua_file 才会生效.

http {
  lua_code_cache off;
}

location ~* /(\d+-.*)/api/orgunits/load_all(.*) {
   default_type 'application/json;charset=utf-8';
   content_by_lua_file /data/projects/xxx/current/lua/controller/load_data.lua;
}

This entry was posted on Tue, 10 Sep 2013 02:46:00 GMT and Posted in . You can follow any any response to this entry through the Atom feed. You can leave a comment or a trackback from your own site.

Tags , , ,


Trackbacks

Use the following link to trackback from your own site:
http://wxianfeng.com/trackbacks?article_id=311

Comments

  1. Avatar
    Victor about {{count}} years ago:

    Helpful information. Lucky me I discovered your web site by accident, and I’m surprised why this accident didn’t came about
    earlier! I bookmarked it.

  2. Avatar
    Victor about {{count}} years ago:

    Hellful information. Lucky me I discovered your web site by accident, and I’m
    surprised why this acciudent didn’t cazme aboutt earlier!
    I bookmarked it.

Leave a comment