apisix icon indicating copy to clipboard operation
apisix copied to clipboard

自定义插件在_M.access中获取为nil

Open StretchV opened this issue 5 years ago • 3 comments

我在自定义的插件中分别打印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)’,此路由只加了这一个插件,请问这可能的原因是什么呢,或者排查的思路应该是什么呢

StretchV avatar Mar 22 '21 05:03 StretchV

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)

spacewander avatar Mar 22 '21 05:03 spacewander

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.

Firstsawyou avatar Mar 22 '21 05:03 Firstsawyou

Thank you for the reminder

StretchV avatar Mar 22 '21 05:03 StretchV