这里主要用到一个方法就是ngx.log,这个方法能够将日志输出到error.log里面,支持多种级别消息,以下:php
ngx.STDERR ngx.EMERG ngx.ALERT ngx.CRIT ngx.ERR ngx.WARN ngx.NOTICE ngx.INFO ngx.DEBUG
能够经过如下方式输出调试信息,大多数状况下咱们只要使用一个来输出咱们的调试信息就行了,好比ngx.ALERT,我就比较喜欢这个,而且设置为个人idea live template了,只须要sout + TAB 就能够输出,关于idea有不少玩法,有时间能够分享给你们,就里就不说了nginx
lua/hello.luagit
ngx.say('print to browser') ngx.log(ngx.ALERT, 'print to error.log') ngx.log(ngx.STDERR, 'print to error.log') ngx.log(ngx.EMERG, 'print to error.log') ngx.log(ngx.ALERT, 'print to error.log') ngx.log(ngx.CRIT, 'print to error.log') ngx.log(ngx.ERR, 'print to error.log') ngx.log(ngx.WARN, 'print to error.log') ngx.log(ngx.NOTICE, 'print to error.log') ngx.log(ngx.INFO, 'print to error.log') ngx.log(ngx.DEBUG, 'print to error.log')
而后用浏览器访问 http://localhost/lua/hello 查看浏览器输出,还有 logs/error.log 文件输出,就能明白大概的意思了,也不用过多解释github
固然nginx里面还能够配置error日志级别,以下web
error_log logs/error.log notice;
这句默认会在nginx.conf文件里面,只是注释掉了而已,只要打开注释就能够了,这样咱们就能够直接经过print来输出日志了,彻底是lua自带的函数,不少代码拿过来就能够直接使用windows
示例代码 参见demo6部分浏览器