feat: change log level based on response status code#3107
feat: change log level based on response status code#3107fawni wants to merge 1 commit intoactix:masterfrom
Conversation
|
Hi @fawni, I was thinking to do a similar thing, but instead of directly set a log level for a response type (which still do make sense), I was thinking to set the log level as parameter, and than filter the range of status to log, for the range filtering I did already a PR here : #3086 so let the user choose a what level to log request, with multiple loggers, something like: Logger::new("....").statuses(StatusCode::OK..StatusCode::BAD_REQUEST).level(Level::Info)
Logger::new("....").statuses(StatusCode::BAD_REQUEST..).level(Level::Warn)WDYT ? |
|
In middleware, any response (regardless of status code) that is sent is considered a success. Logging as INFO level is the policy of this textual logger. If you want to separately track errors, I encourage you to write a middleware to add in your stack. Also, we're gradually transitioning to the Thank you for your ideas and contribution. |
PR Type
Feature
PR Checklist
Overview
Changes the log level to
Warnon client errors and redirection messages, and toErroron server errors.The current behavior is to log everything on an
Infolevel.This helps logging crates customize the output. Here's an example using the femme crate:
Before:
After:
It would also be colored red on a 5xx status code.
I do not know how to test or document those changes so I apologize if I should have done that.