apache / apisix-go-plugin-runner

Go Plugin Runner for APISIX
https://apisix.apache.org/
Apache License 2.0
167 stars 69 forks source link

bug: Logging using `pkg/log` does not work #149

Open Blinkuu opened 7 months ago

Blinkuu commented 7 months ago

Issue description

I followed the blog post describing how to implement an external plugin using Go SDK. I've successfully managed to connect APISIX with my plugin process. On top of that, I can see logs being printed to stdout:

2023-11-13T15:37:38.412Z        INFO    plugin/plugin.go:73     register plugin fault-injection
2023-11-13T15:37:38.412Z        INFO    plugin/plugin.go:73     register plugin limit-req
2023-11-13T15:37:38.412Z        INFO    plugin/plugin.go:73     register plugin response-rewrite
2023-11-13T15:37:38.412Z        INFO    plugin/plugin.go:73     register plugin say
2023-11-13T15:37:38.412Z        WARN    server/server.go:192    conf cache ttl is 1h12m0s
2023-11-13T15:37:38.412Z        WARN    server/server.go:200    listening to /tmp/runner.sock
2023-11-13T15:37:52.667Z        INFO    server/server.go:115    Client connected (unix)
2023-11-13T15:37:52.667Z        INFO    server/server.go:115    Client connected (unix)
2023-11-13T15:37:52.667Z        INFO    server/server.go:131    receive rpc type: 1 data length: 136
2023-11-13T15:37:52.667Z        INFO    plugin/conf.go:98       prepare conf for plugin say
2023-11-13T15:37:52.668Z        INFO    server/server.go:131    receive rpc type: 2 data length: 652
2023-11-13T15:37:52.668Z        INFO    plugin/plugin.go:120    run plugin say
2023-11-13T15:37:53.290Z        INFO    server/server.go:115    Client connected (unix)
2023-11-13T15:37:53.290Z        INFO    server/server.go:115    Client connected (unix)
2023-11-13T15:37:53.290Z        INFO    server/server.go:131    receive rpc type: 2 data length: 652
2023-11-13T15:37:53.291Z        INFO    plugin/plugin.go:120    run plugin say

I tried adding my own logs by importing the github.com/apache/apisix-go-plugin-runner/pkg/log package and using it inside my RequestFilter(...) implementation:

func (p *Say) RequestFilter(conf interface{}, w http.ResponseWriter, r pkgHTTP.Request) {
    log.Infof("Hello from Go plugin!") // This doesn't get printed to `stdout`, no matter the level.

    body := conf.(SayConf).Body
    if len(body) == 0 {
        return
    }
}

However, I actually don't see any logs I created being printed.

Environment

Minimal test code / Steps to reproduce the issue

N/A

What's the actual result? (including assertion message & call stack if applicable)

I see both INFO and WARN logs from places like server/server.go and plugin/plugin.go.

What's the expected result?

I expect to see my own logs.