How to debug kong plugin?

I have enabled my custom plugin successfully, but I have no way to know whether it is executed it no not.

my plugin is enabled globally

the access method of the handler should execute when a request received , but even though I add a none existed method breakhere, no error happened.

handler.lua


function ApiStats:access(conf)
     breakhere()
    ApiStats.super.log(self)

    local ok, err = buffer.init({
        host = conf.host,
        port = conf.port,
        proto = conf.proto,
        db = conf.db,
        auth = conf.username and conf.password and conf.username.. ":" ..conf.password or Nil
    })

    if (not ok) then
        ngx.log(ngx.ERR, err)
        return false
    end

    ApiStats.setupFlushHandler()

    local point = influxdb_point(ngx, conf)
    buffer.buffer(point)

    return true, point
end

are you getting logs when you run ngx.log instead of breakhere() (wondering if your plugin is even executing this file)? If you are editing the files and looking for immediate feedback, you will need to restart Kong with each code change.

thanks, I see that error in kong error log.

1 Like