Skip to content

Commit

Permalink
Add WriteErrorToDefaultLogger function to log errors in ECS agent def…
Browse files Browse the repository at this point in the history
…ault logger
  • Loading branch information
chienhanlin committed Sep 18, 2020
1 parent 579828f commit 33ce793
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions agent/handlers/utils/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ func WriteJSONToResponse(w http.ResponseWriter, httpStatusCode int, responseJSON
"Unable to write %s json response message to ResponseWriter",
requestType)
}

WriteErrorToDefaultLogger(httpStatusCode, responseJSON, requestType)
}

// WriteResponseIfMarshalError checks the 'err' response of the json.Marshal function.
Expand Down Expand Up @@ -129,3 +131,10 @@ func LimitReachedHandler(auditLogger audit.AuditLogger) func(http.ResponseWriter
auditLogger.Log(logRequest, http.StatusTooManyRequests, "")
}
}

// WriteErrorToDefaultLogger write the requestType, httpStatusCode and responseJSON of error to the default logger
func WriteErrorToDefaultLogger(httpStatusCode int, responseJSON []byte, requestType string) {
if httpStatusCode >= 400 && httpStatusCode <= 599 {
seelog.Errorf("HTTP response status code is '%d', request type is: %s, and response in JSON is %s", httpStatusCode, requestType, string(responseJSON))
}
}

0 comments on commit 33ce793

Please sign in to comment.