<p>Here's what the code looks like that starts my server:</p>
<pre><code>func startServer() {
router := getRouter()
port := getPort()
log.Println("Starting up app on port " + port + "...")
log.Fatal(http.ListenAndServe(":"+port, handlers.LoggingHandler(os.Stdout, router)))
}
</code></pre>
<p>The issue is that I have a health check route that's being pinged every 10 seconds to make sure it's alive, but I don't want the app to log that request to stdout because then our logging service picks it up. I need all other routes logged normally though. Is there a way to say "hey, don't log anything for this one route"?</p>
<hr/>**评论:**<br/><br/>shovelpost: <pre><p>You either need to add <code>handlers.LoggingHandler()</code> in all routes except the one that needs to avoid logging or add special code in <code>handlers.LoggingHandler()</code> to recognize the route that needs to avoid logging.</p></pre>aminoglycine: <pre><p>Ah, thank you. I should have checked gorilla's handlers readme, it had an example right in there: <a href="https://github.com/gorilla/handlers#example" rel="nofollow">https://github.com/gorilla/handlers#example</a></p></pre>mcouturier: <pre><p>Or register your health check handler as a Middleware just before your logging Middleware. Easy.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传