mirror of
https://github.com/drakkan/sftpgo.git
synced 2024-11-22 07:30:25 +00:00
httpd request logger: set log level based on the status code
Fixes #1393 Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
parent
ce8dbda44b
commit
397cad93df
1 changed files with 9 additions and 1 deletions
|
@ -73,7 +73,15 @@ func (l *StructuredLogger) NewLogEntry(r *http.Request) middleware.LogEntry {
|
||||||
// Write logs a new entry at the end of the HTTP request
|
// Write logs a new entry at the end of the HTTP request
|
||||||
func (l *StructuredLoggerEntry) Write(status, bytes int, _ http.Header, elapsed time.Duration, _ any) {
|
func (l *StructuredLoggerEntry) Write(status, bytes int, _ http.Header, elapsed time.Duration, _ any) {
|
||||||
metric.HTTPRequestServed(status)
|
metric.HTTPRequestServed(status)
|
||||||
l.Logger.Info().
|
var ev *zerolog.Event
|
||||||
|
if status >= http.StatusInternalServerError {
|
||||||
|
ev = l.Logger.Error()
|
||||||
|
} else if status >= http.StatusBadRequest {
|
||||||
|
ev = l.Logger.Warn()
|
||||||
|
} else {
|
||||||
|
ev = l.Logger.Debug()
|
||||||
|
}
|
||||||
|
ev.
|
||||||
Timestamp().
|
Timestamp().
|
||||||
Str("sender", "httpd").
|
Str("sender", "httpd").
|
||||||
Fields(l.fields).
|
Fields(l.fields).
|
||||||
|
|
Loading…
Reference in a new issue