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 , 非常麻烦. 解决办法如下:


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

local inspect = require "inspect"
local a = { retCode =  1 }

查看输出 或者错误

查看 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 , , ,


Use the following link to trackback from your own site:


Leave a comment