[英]How to change priorities of messages logged by buffalo router
I updated question for clarity (as requested).为了清楚起见,我更新了问题(按要求)。
I use Buffalo framework.我使用 Buffalo 框架。 I have lots of messages in logs informing that someone on the internet tries to reach nonexistent endpoint or uses HTTP method that is not supported by the service.
我在日志中有很多消息,通知 Internet 上的某个人尝试访问不存在的端点或使用服务不支持的 HTTP 方法。 I think, these messages originates from Buffalo's router (definitely not from my code).
我认为,这些消息来自 Buffalo 的路由器(绝对不是来自我的代码)。 Here is an example of a message: "method not found: HEAD /some/path".
这是一条消息示例:“找不到方法:HEAD /some/path”。
Question: how I can change priority of these messages from "error" to "notice" or "info".问题:如何将这些消息的优先级从“错误”更改为“通知”或“信息”。 In my opinion, an such a hi priority is a bad choice for messages that indicates errors on client side, and not in my code.
在我看来,对于在客户端而不是在我的代码中指示错误的消息来说,如此高的优先级是一个糟糕的选择。
Original content:原文内容:
Why messages like "method not found: HEAD /some/path" are logged with an "error" priority?为什么像“方法未找到:HEAD /some/path”之类的消息以“错误”优先级记录? How can I change the priority to "notice" or "info" for that kind of messages?
如何将此类消息的优先级更改为“通知”或“信息”? Reason: I don't like being woken up every time some kiddie on the internet tries new script on my site.
原因:我不喜欢每次互联网上的一些小孩在我的网站上尝试新脚本时被吵醒。
Here is my router configuration:这是我的路由器配置:
app.GET("/{path:.+}", fs)
app.GET("/", fs)
fs
is regular http.Handler
wrapped using buffalo.WrapHandler()
. fs
是使用buffalo.WrapHandler()
包装的常规http.Handler
。
I digged through the code and it seems there is no easy way to do what I want (no configuration option).我仔细研究了代码,似乎没有简单的方法可以做我想做的事情(没有配置选项)。
But one can provide custom error handler:但是可以提供自定义错误处理程序:
func App() *buffalo.App {
app = buffalo.New(buffalo.Options{
// ...
})
app.ErrorHandlers[405] = errorHandler
}
func errorHandler(status int, origErr error, c Context) error {
//...
}
defaultErrorHandler
(used when custom is not provided) in its 4-th line writes error message to logs. defaultErrorHandler
(未提供自定义时使用)在其第 4 行中将错误消息写入日志。 Unfortunately it does a lots of other things too.不幸的是,它也做了很多其他的事情。 It is 74 lines long and provide different behavior based on request's content type and environment the application is run in (development, test, production).
它有 74 行,根据请求的内容类型和应用程序运行的环境(开发、测试、生产)提供不同的行为。 And it can not be easily copy-and-paste as it uses private functions and types.
它不能轻易复制和粘贴,因为它使用私有函数和类型。
Seems like I need to ask for new feature.似乎我需要要求新功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.