Kong / go-pdk

Write Kong plugins in Go! 🦍
https://pkg.go.dev/github.com/Kong/go-pdk
Apache License 2.0
146 stars 50 forks source link

How can I print log to log_file? #134

Closed LiPeio-o closed 7 months ago

LiPeio-o commented 1 year ago

I wrote a plugin in golang,and print log like this:

func (config Config) Access(kong *pdk.PDK) {
    kong.Log.Err("hello world Err")
    kong.Log.Warn("hello world Warn")
    kong.Log.Alert("hello world Alert")
    kong.Log.Debug("hello world debug")
    kong.Log.Info("hello world Info")
    kong.Log.Notice("hello world Notice")
}

this plugin imported

github.com/Kong/go-pdk v0.5.0

and add config :

log_level = debug

then I installed this plugin on my service and and send requests, but no log is printed out in the log files as expected (i checked access.log, admin_access.log and error.log)

so how can I print out the log correctly?

Thankyou!

StarlightIbuki commented 1 year ago

Thank you for your report. I tested your case and it works as expected. Could you share more details, like how you configured the plugin(i.e, does it attach to some routes, services, or just global)? You could also debug this yourself. Just as an example, try to write a file in this handler to see if it is really executed.

LiPeio-o commented 1 year ago

Thanks for reply~ I deployed kong in hybrid mode with a CP node and a DP node, and I installed the plugin to print log on both CP node and DP node. Then I send requests but not found any log in the both two nodes no matter attach plugin to service or global. (I also test deployed in traditional mode, and the plugin works correctly, I can see logs in kong/logs/errors.log). Looking forward to your reply, thank you!

StarlightIbuki commented 1 year ago

Sorry I missed the important information. You said you are using v0.5.0. Please change to the latest version, as the gateway doesn't have version compatibility as the recent updates make breaking changes.

LiPeio-o commented 1 year ago

The kong version we‘re using is 2.2.1. And I think the version of kong is compatible with the version of pdk because we have developed several plugins using go-pdk@v0.5.0. We have deployed many services and did secondary development based on the kong gateway 2.2.1, so we tend to use the current version of kong beacause the upgrade should be evaluate carefully... So is there any way to print out the log correctly in hybrid mode using the kong and go pdk we're currently using?Thank you so much!

StarlightIbuki commented 1 year ago

I thought you were using the latest version of Kong and that is not compatible with go-pdk@v0.5.0. I will investigate your issue later.

Tolsee commented 1 year ago

I am using kong:3.0.0-alpine and go-pdk@v0.8.0, it is not working for these combinations as well. @StarlightIbuki Is there any guide docs regarding compatibility/version requirement? Thank you.

StarlightIbuki commented 1 year ago

@Tolsee go-pdk@v0.8.0 works with kong 3.1.0.

dhyaniarun1993 commented 1 year ago

@Tolsee go-pdk@v0.8.0 works with kong 3.1.0.

For me this isn't working as well. I also tried with kong 3.1.1 and that also doesn't work.

StarlightIbuki commented 1 year ago

@Tolsee go-pdk@v0.8.0 works with kong 3.1.0.

For me this isn't working as well. I also tried with kong 3.1.1 and that also doesn't work.

Could you provide more detailed information? For example the log, the stdout print, etc.

Tolsee commented 1 year ago

@Tolsee go-pdk@v0.8.0 works with kong 3.1.0.

This worked for me.

gszr commented 7 months ago

Closing as resolved - please reopen if the issue persists with the latest go-pdk (0.10.0) and newer Kong versions.