Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix contextual logging #153

Merged
merged 1 commit into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions handlers/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ func (d *CatalystAPIHandlersCollection) UploadVOD() httprouter.Handle {
RequestID: requestID,
})

log.Log(requestID, "Beginning segmenting")

// process the request
if err := d.processUploadVOD(streamName, uploadVODRequest.Url, targetSegmentedOutputURL.String()); err != nil {
errors.WriteHTTPInternalServerError(w, "Cannot process upload VOD request", err)
Expand Down
9 changes: 7 additions & 2 deletions log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ func init() {

// Permanently add context to the logger. Any future logging for this Request ID will include this context
func AddContext(requestID string, keyvals ...interface{}) {
_ = loggerCache.Add(requestID, kitlog.With(getLogger(requestID), keyvals...), default_logger_cache_expiry)
logger := kitlog.With(getLogger(requestID), keyvals...)

err := loggerCache.Replace(requestID, logger, default_logger_cache_expiry)
if err != nil {
_ = logger.Log("msg", "error replacing logger in cache: "+err.Error())
}
}

func Log(requestID string, message string, keyvals ...interface{}) {
Expand Down Expand Up @@ -46,7 +51,7 @@ func getLogger(requestID string) kitlog.Logger {
newLogger := kitlog.With(newLogger(), "request_id", requestID)
err := loggerCache.Add(requestID, newLogger, default_logger_cache_expiry)
if err != nil {
_ = newLogger.Log("msg", "error adding logger to cache", "request_id", requestID)
_ = newLogger.Log("msg", "error adding logger to cache", "request_id", requestID, "err", err.Error())
}
return newLogger
}
Expand Down