go-zero icon indicating copy to clipboard operation
go-zero copied to clipboard

Is it possible to merge http access logs and slow logs in rest?

Open marsmay opened this issue 1 year ago • 3 comments
trafficstars

1. Is it possible to merge http access logs and slow logs in rest? When a request is too slow, the slow call log is triggered, and the access log of the request is also triggered, the information of these two logs is almost exactly the same, is it possible to consider not printing the access log anymore after outputting the slow call log?

2. Is it possible to configure an exception path for slow call logs? In my project using websocket, the connection time is usually more than 60 seconds and almost every request prints the slow call log when the connection is closed, this is normal, tell me that the request is too slow is completely pointless and is a distraction.

2024-02-13T14:53:27.102+08:00    slow   [HTTP]  200  -  GET  /user/chat/ws?k_sso_token=l5NVP1jEaOOjavdlXAaY0GxW-vnBV9_Dga4SqIDSsnPqJXtO3x17TLLCm5N9tPOC86M7yzQ5nDNvuKBpJknkBC_cN4ifK9_KdmfupEWDiMFO700L-2NiYorNK65IrCPb4X4pOnq-ZIjbs_imlOebdhbYVm_RkD-Z3fHfttyoccQ.cv0 - 127.0.0.1:56662 - Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.3 Safari/605.1.15 - slowcall(19439.3ms)      duration=19439.3ms      caller=handler/loghandler.go:131        trace=a136e9df9c8329e8f22723e849c869e8    span=e2f34239c27f457d
2024-02-13T14:53:27.102+08:00    info   [HTTP]  200  -  GET  /user/chat/ws?k_sso_token=l5NVP1jEaOOjavdlXAaY0GxW-vnBV9_Dga4SqIDSsnPqJXtO3x17TLLCm5N9tPOC86M7yzQ5nDNvuKBpJknkBC_cN4ifK9_KdmfupEWDiMFO700L-2NiYorNK65IrCPb4X4pOnq-ZIjbs_imlOebdhbYVm_RkD-Z3fHfttyoccQ.cv0 - 127.0.0.1:56662 - Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.3 Safari/605.1.15    duration=19439.3ms      caller=handler/loghandler.go:147        trace=a136e9df9c8329e8f22723e849c869e8  span=e2f34239c27f457d

marsmay avatar Feb 13 '24 07:02 marsmay

You can set the log writer, check out the example here: https://github.com/zeromicro/zero-contrib/tree/main/logx/zapx

kevwan avatar Feb 15 '24 09:02 kevwan

I got the same problem, is there any good solution?

Suyghur avatar Apr 24 '24 08:04 Suyghur