Merge pull request #228 from Azure/issue/http-log-policy

Issue/http log policy
This commit is contained in:
Mohit Sharma 2020-11-11 10:24:50 +05:30 коммит произвёл GitHub
Родитель 6d84fabf1c 28f9c3868c
Коммит e5968b22f5
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 14 добавлений и 8 удалений

Просмотреть файл

@ -62,15 +62,21 @@ func NewRequestLogPolicyFactory(o RequestLogOptions) pipeline.Factory {
logLevel, forceLog = pipeline.LogWarning, true
}
if err == nil { // We got a response from the service
sc := response.Response().StatusCode
if ((sc >= 400 && sc <= 499) && sc != http.StatusNotFound && sc != http.StatusConflict && sc != http.StatusPreconditionFailed && sc != http.StatusRequestedRangeNotSatisfiable) || (sc >= 500 && sc <= 599) {
logLevel, forceLog = pipeline.LogError, true // Promote to Error any 4xx (except those listed is an error) or any 5xx
} else {
// For other status codes, we leave the level as is.
var sc int
if err == nil { // We got a valid response from the service
sc = response.Response().StatusCode
} else { // We got an error, so we should inspect if we got a response
if se, ok := err.(StorageError); ok {
if r := se.Response(); r != nil {
sc = r.StatusCode
}
}
} else { // This error did not get an HTTP response from the service; upgrade the severity to Error
logLevel, forceLog = pipeline.LogError, true
}
if sc == 0 || ((sc >= 400 && sc <= 499) && sc != http.StatusNotFound && sc != http.StatusConflict && sc != http.StatusPreconditionFailed && sc != http.StatusRequestedRangeNotSatisfiable) || (sc >= 500 && sc <= 599) {
logLevel, forceLog = pipeline.LogError, true // Promote to Error any 4xx (except those listed is an error) or any 5xx
} else {
// For other status codes, we leave the level as is.
}
if shouldLog := po.ShouldLog(logLevel); forceLog || shouldLog {