ziflex / lecho

Zerolog wrapper for Echo framework 🍅
MIT License
97 stars 11 forks source link

Run Enricher after next to allow access to request specific context information #26

Open bumi opened 1 year ago

bumi commented 1 year ago

Currently it is not possible to use the Enricher to log context specific information that is added from other middlewares like for example the user ID.

Could calling the Enricher be moved to after the next() call to be able to log such information?

For example I have a middleware that loads sets the UserID in the context and wanted to add this information to the request logs.

Enricher: func(c echo.Context, logger zerolog.Context) zerolog.Context {
  userId := c.Get("UserID")
  if userId != nil {
    return logger.Str("user_id", userId.(string))
  }
  return logger.Str("user_id", "")
}
ziflex commented 1 year ago

Hey, why don't you put that middleware before the logger middleware? In this case, enricher will have all required data.