简体   繁体   English

如何更改 buffalo 路由器记录的消息的优先级

[英]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.

相关问题 如何检查访问者是否从 plush 模板登录? 使用 go Buffalo 框架 - How can I checked if the visitor is logged in from a plush template? Using the go Buffalo framework 如何使 Buffalo 事务中间件提交? - How to cause Buffalo transaction middleware to commit? 如何使用Go Buffalo框架呈现Quill js内容 - How to render the quill js content using go buffalo framework 如何在Buffalo中从新文章网址重定向到表演文章网址 - How to redirect from a new post url to the show post url in Buffalo 如何在使用 Go Buffalo 框架的开发环境中使用 TOML fixtures 为我的数据库播种? - How can I use TOML fixtures to seed my database in a development environment using the Go Buffalo framework? 通过中间件配置时,如何允许Buffalo(gobuffalo)中间件的skip()方法? - How do I allow the skip() method for Buffalo (gobuffalo) middleware when I'm passing the middleware config? 在水牛城里反向路由 - Reverse routing in buffalo 安装 gobuffalo 后如何修复“/gobuffalo/buffalo/plugins/plugdeps/plugin.go:15:11: undefined: meta.BuildTags”错误 - How to fix '/gobuffalo/buffalo/plugins/plugdeps/plugin.go:15:11: undefined: meta.BuildTags' error after installing gobuffalo 在 buffalo 中调试单个测试函数 - Debugging a single test function in buffalo 在 Buffalo 中集成 Sentry 和 Elastic APM - Integrating Sentry and Elastic APM in Buffalo
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM