openresty / lua-resty-core

New FFI-based API for lua-nginx-module
801 stars 272 forks source link

how to set error log level ? #396

Closed matianhe3 closed 2 years ago

matianhe3 commented 2 years ago

It only shows the "ERR".

    server {
        preread_by_lua_block{
            local errlog = require "ngx.errlog"
            errlog.set_filter_level(ngx.DEBUG)     
            ngx.log(ngx.WARN, "WARN")
          ngx.log(ngx.ERR, "ERR")
      }
 }
cppcoffee commented 2 years ago

The set_filter_level API used in the init_by_lua* init phase.

https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/errlog.md#set_filter_level

matianhe3 commented 2 years ago

This ok? also can't work.

http {
    lua_capture_error_log 100k;

    init_by_lua_block {
        local errlog = require "ngx.errlog"
        local status, err = errlog.set_filter_level(ngx.WARN)
        if not status then
            ngx.log(ngx.ERR, err)
            return
        end
        ngx.log(ngx.WARN, "set error filter level: WARN")
        ngx.log(ngx.ERR, "set error filter level: ERR")
    }
}
stream {
 .....
}
zhuizhuhaomeng commented 2 years ago

you should change the error log level in nginx.conf errlog.set_filter_level set the filter for the ringbuf of the error log which should be get by errlog.get_logs

matianhe3 commented 2 years ago

you should change the error log level in nginx.conf errlog.set_filter_level set the filter for the ringbuf of the error log which should be get by errlog.get_logs

it's right, thanks.