简体   繁体   中英

How to change priorities of messages logged by buffalo router

I updated question for clarity (as requested).

I use Buffalo framework. 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. I think, these messages originates from Buffalo's router (definitely not from my code). Here is an example of a message: "method not found: 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? 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() .

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. 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). 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM