网站首页lua/js

nginx_lua记录调试信息

发布时间:2017-05-13 01:55:04编辑:slayer.hvoer阅读(4595)

    1. 在server部分加上记录调试日志的输出路径。

    server{        
        listen       80;        
        server_name  lua.com;        
        root   /home/webroot/web;        
        index  index.html;
            
        location /test {                
            default_type 'text/html';                
            content_by_lua_file /usr/local/nginx/conf/lua/test.lua;        
        }
            
        access_log  /home/logs/lua/access.log access;        
        error_log     /home/logs/lua/debug.log debug;
    }


    2. 在lua文件中加入记录日志代码test.lua

    local function log(msg)    
        ngx.log(ngx.DEBUG, msg)
    end
    
    log("hello, world!")

    这样,执行在浏览器里访问过后, 就会在/home/logs/lua/debug.log里有记录下日志了。


    3. nginx log配置中可使用的日志级别:
    nginx支持的日志级别主要有emerg、alert、crit、error、warn、notice、info、debug。

    main部分默认是error级别、HTTP部分默认是crit级别,server部分默认是crit级别。

    #define NGX_LOG_STDERR            0
    #define NGX_LOG_EMERG             1
    #define NGX_LOG_ALERT             2
    #define NGX_LOG_CRIT              3
    #define NGX_LOG_ERR               4
    #define NGX_LOG_WARN              5
    #define NGX_LOG_NOTICE            6
    #define NGX_LOG_INFO              7
    #define NGX_LOG_DEBUG             8


    当server配置项中的配置level值大于等于当前日志的level值时,才调用ngx_log_error_core函数将用户信息存于日志文件中。

    如此,配置"error_log     /home/logs/lua/debug.log debug;"后日志文件中只会记录我们的debug输出信息了。

评论