You can’t “require kong.log” so calling kong.log.inspect(“text”) (for example) doesn’t work from there. Is that correct or am I missing something?
As a workaround - I’ve created some “util” functions in access.lua that call kong.log.* and the access.lua in a plugin can be mentioned in the require.
Hi,
Indeed, the plugin SDK is not yet available for consumption in the Admin API plugin extensions (i.e. api.lua
).
That said, the SDK is provided as a global, so no require
should be necessary. Please post any issue you may be encountering if that is not the behaviour you have observed.
As a workaround - I’ve created some “util” functions in access.lua that call kong.log.* and the access.lua in a plugin can be mentioned in the require.
The issue I am seeing here is that since the runloop updates the namespace of the kong.log
global (roughly speaking) during plugin execution (see here), you will likely end up in situations in which the name of other plugins will appear to be randomly injected in logs produced via your api.lua
extension, as in:
-- api.lua
kong.log("hello world")
could produce logs with inconsistent namespaces such as:
2017/07/09 19:36:25 [notice] 2593#0: *1 [key-auth] api.lua:54 hello world, [...]
2017/07/09 19:36:25 [notice] 2593#0: *1 [kong] api.lua:54 hello world, [...]
2017/07/09 19:36:25 [notice] 2593#0: *1 [rate-limiting] api.lua:54 hello world, [...]
In which the source file and line number are correct, but the namespace fluctuates depending on which plugin is currently being executed by the runloop at the time the Admin API request is served.
We do have plans to allow the use of the SDK in api.lua
in the future (we could even consider using a better namespace reflecting that the log is produced on the Admin API). For now, if this is a minor inconvenience for you, you could stick with it with minor consequences, or consider using the raw ngx.log
API.