Debugging 如何在nginx config中调试lua代码?

Debugging 如何在nginx config中调试lua代码?,debugging,nginx,lua,Debugging,Nginx,Lua,我想在我的lua代码中插入日志点(io.write),该代码本身在nginx配置中(使用HttpLuaModule for nginx)。 怎么做? 访问和错误日志没有显示它们 在nginx下运行时,应该使用ngx.log。例如: ngx.log(ngx.STDERR,“您的信息在这里”) 有关工作示例,请参见 有关文档,请参见nginx中Lua调试的另一个选项(除了“打印”)是使用支持远程调试的Lua IDE。我发布了如何使用ZeroBrane Studio IDE实现这一点。设置好后,您将获

我想在我的lua代码中插入日志点(io.write),该代码本身在nginx配置中(使用HttpLuaModule for nginx)。 怎么做?
访问和错误日志没有显示它们

在nginx下运行时,应该使用ngx.log。例如:

ngx.log(ngx.STDERR,“您的信息在这里”)

有关工作示例,请参见


有关文档,请参见

nginx中Lua调试的另一个选项(除了“打印”)是使用支持远程调试的Lua IDE。我发布了如何使用ZeroBrane Studio IDE实现这一点。设置好后,您将获得预期的大部分调试功能,如步进、断点、变量检查、堆栈跟踪和远程运行Lua命令的控制台。

openresty的另一个故障排除工具是,它允许您检查Lua变量、导入的模块、调用函数等。 您所要做的就是使用Luarock安装它,并在nignx.conf中插入几行代码。启动客户端,然后开始

[9] ngx(content)> ngx.config.prefix()
=> /workspace/lua-resty-console/
[10] ngx(content)> ngx.config.ngx_lua_version
=> 10011
[11] ngx(content)> ngx.config.nginx_configure()
=>  --prefix=/usr/local/Cellar/openresty/1.13.6.1/nginx --with-cc-opt='-O2 -I/usr/local/include -I/usr/local/opt/pcre/include -I/usr/local/opt/openresty-openssl/include' --add-module=../ngx_devel_kit-0.3.0 --add-module=../echo-nginx-module-0.61 ...


[12] ngx(content)> ngx.sha →→
ngx.sha1_bin()  ngx.shared.     
[12] ngx(content)> ngx.shared. →→
ngx.shared.mycache.    ngx.shared.metrics.  
[12] ngx(content)> c = ngx.shared.mycache
=> nil
[13] ngx(content)> c
=> { <userdata 1>,
  <metatable> = <1>{
    __index = <table 1>,
    add = <function 1>,
    delete = <function 2>,
    flush_all = <function 3>,
    flush_expired = <function 4>,
    get = <function 5>,
    get_keys = <function 6>,
    get_stale = <function 7>,
    incr = <function 8>,
    llen = <function 9>,
    lpop = <function 10>,
    lpush = <function 11>,
    replace = <function 12>,
    rpop = <function 13>,
    rpush = <function 14>,
    safe_add = <function 15>,
    safe_set = <function 16>,
    set = <function 17>
  }
}
[14] ngx(content)> c:set('a', 1)
=> true
[15] ngx(content)> c:get('a')
=> 1
[16] ngx(content)> c:get_keys()
=> { "a" }
[9]ngx(content)>ngx.config.prefix()
=>/workspace/lua resty控制台/
[10] ngx(内容)>ngx.config.ngx\u lua\u版本
=> 10011
[11] ngx(content)>ngx.config.nginx_configure()
=>--prefix=/usr/local/ceral/openresty/1.13.6.1/nginx--with cc opt='-O2-I/usr/local/include-I/usr/local/opt/pcre/include-I/usr/local/opt/openresty-openssl/include'--add module=../ngx\u-devel\u-kit-0.3.0--add module=../echo-nginx-module-0.61。。。
[12] ngx(内容)>ngx.sha→→
ngx.sha1_bin()ngx.shared。
[12] ngx(内容)>ngx.shared。→→
ngx.shared.mycache。ngx.shared.metrics。
[12] ngx(content)>c=ngx.shared.mycache
=>零
[13] ngx(含量)>c
=> { ,
= {
__索引=,
加法=,
删除=,
全部刷新=,
刷新\u已过期=,
获取=,
获取_键=,
get_stale=,
增量=,
艾伦=,,
lpop=,
lpush=,
替换=,
rpop=,
rpush=,
安全添加=,
安全集合=,
集合=
}
}
[14] ngx(内容)>c:set('a',1)
=>正确
[15] ngx(content)>c:get('a')
=> 1
[16] ngx(content)>c:get_key()
=>{“a”}

谢谢你,保罗。我将尝试这种方法。我更喜欢这种工作方式,而不是一直打印值。有没有办法更改日志消息格式?目前我收到了一条很长的信息,包括日期、主机等。“2017/03/03 05:31:22[]44#0:*17[lua]content_by_lua(proj1.conf:110):3:您的消息在这里,客户端:172.18.0.1,服务器: