自定义插件在_M.access中获取为nil
我在自定义的插件中分别打印ctx:
function _M.rewrite(conf, ctx)
core.log.error("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
core.log.error(core.json.encode(ctx, true))
core.log.error("````````````````````````````")
end
function _M.access(conf, ctx)
core.log.error(core.json.encode(ctx))
end
结果在日志中rewrite的可以成功打印出来,但是access中的打印为‘phase_func():nilCannot serialise, excessive nesting (1001)’,此路由只加了这一个插件,请问这可能的原因是什么呢,或者排查的思路应该是什么呢
It is fine. There may be some unserializable fields added after the rewrite phase.
You can dump the exact key instead, like core.json.encode(ctx.blah), or using core.json.encode(ctx, true)
function _M.access(conf, ctx) core.log.error(core.json.encode(ctx)) end
In the access phase, you should print the ctx parameters like this: function _M.access(conf, ctx) core.log.error(core.json.encode(ctx, true)) end
By the way, it would be better if you use English.
Thank you for the reminder