Better duration formatting in logs

This commit is contained in:
Deluan 2021-02-03 13:04:20 -05:00
parent 9668263235
commit 618d5fc81f
3 changed files with 71 additions and 2 deletions

View file

@ -7,6 +7,7 @@ import (
"net/http"
"runtime"
"strings"
"time"
"github.com/sirupsen/logrus"
)
@ -171,8 +172,12 @@ func addFields(logger *logrus.Entry, keyValuePairs []interface{}) *logrus.Entry
if i+1 >= len(keyValuePairs) {
logger = logger.WithField(name, "!!!!Invalid number of arguments in log call!!!!")
} else {
value := keyValuePairs[i+1]
logger = logger.WithField(name, value)
switch v := keyValuePairs[i+1].(type) {
case time.Duration:
logger = logger.WithField(name, ShortDur(v))
default:
logger = logger.WithField(name, v)
}
}
}
}