Skip to content

Commit

Permalink
feat(deps): use logger from context if available
Browse files Browse the repository at this point in the history
  • Loading branch information
Pitasi committed Mar 3, 2022
1 parent 70ea990 commit a69c256
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion api/router/deps/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,18 @@ func GetDeps(c *gin.Context) *Deps {
panic(fmt.Sprintf("deps not of the expected type, found %T", deps))
}

// override logger with the one from the gin.context
logger, err := logging.GetLoggerFromContext(c)
if err == nil {
deps.Logger = logger
} else {
deps.Logger.Warnw("couldn't get logger from context, using fallback", "error", err)
}

return deps
}

// WriteError lgos and return client-facing errors
// WriteError logs and return client-facing errors
func (d *Deps) WriteError(c *gin.Context, err Error, logMessage string, keyAndValues ...interface{}) {

// setting error id
Expand Down

0 comments on commit a69c256

Please sign in to comment.