Logger log levels are off: please fix them or make them customizable
Closed this issue · 4 comments
Currently the Logger
middleware uses the following mapping:
if (status >= 500) {
logger.fatal(message);
} else if (status >= 400) {
logger.error(message);
} else if (status >= 300) {
logger.warn(message);
} else {
logger.info(message);
}
This is problematic when you use a monitoring system that inspects log lines because client errors (4xx) are reported at the ERROR
level, which is typically the level at which server errors are logged. This leads to a mix of genuine server side errors and client side errors.
Moreover 3x responses are perfectly fine, there's no reason to log them at WARN
level.
So IMO the "correct" mapping should be:
if (status >= 500) {
logger.error(message);
} else if (status >= 400) {
logger.warn(message);
} else {
logger.info(message);
}
I can totally understand that you may not want to change the existing implementation so could you make it possible to alter the the current behaviour either by:
- extracting the above code in a
protected
method that a sub-class can implement differently, - or making the mapping configurable.
Thank you for considering this 😸
I do like the protected override method approach, can you make a PR? :)
Cool, thanks!
Any hope to have this in 2.0.8
?