[#77] Added requests logging
Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
parent
9241156af4
commit
2b8aa4914e
1 changed files with 14 additions and 3 deletions
17
app.go
17
app.go
|
@ -197,11 +197,11 @@ func (a *app) Serve(ctx context.Context) {
|
|||
// Configure router.
|
||||
r := router.New()
|
||||
r.RedirectTrailingSlash = true
|
||||
r.POST("/upload/{cid}", uploader.Upload)
|
||||
r.POST("/upload/{cid}", a.logger(uploader.Upload))
|
||||
a.log.Info("added path /upload/{cid}")
|
||||
r.GET("/get/{cid}/{oid}", downloader.DownloadByAddress)
|
||||
r.GET("/get/{cid}/{oid}", a.logger(downloader.DownloadByAddress))
|
||||
a.log.Info("added path /get/{cid}/{oid}")
|
||||
r.GET("/get_by_attribute/{cid}/{attr_key}/{attr_val:*}", downloader.DownloadByAttribute)
|
||||
r.GET("/get_by_attribute/{cid}/{attr_key}/{attr_val:*}", a.logger(downloader.DownloadByAttribute))
|
||||
a.log.Info("added path /get_by_attribute/{cid}/{attr_key}/{attr_val:*}")
|
||||
// enable metrics
|
||||
if a.cfg.GetBool(cmdMetrics) {
|
||||
|
@ -229,3 +229,14 @@ func (a *app) Serve(ctx context.Context) {
|
|||
a.log.Fatal("could not start server", zap.Error(err))
|
||||
}
|
||||
}
|
||||
|
||||
func (a *app) logger(h fasthttp.RequestHandler) fasthttp.RequestHandler {
|
||||
return fasthttp.RequestHandler(func(ctx *fasthttp.RequestCtx) {
|
||||
a.log.Info("request", zap.String("remote", ctx.RemoteAddr().String()),
|
||||
zap.ByteString("method", ctx.Method()),
|
||||
zap.ByteString("path", ctx.Path()),
|
||||
zap.ByteString("query", ctx.QueryArgs().QueryString()),
|
||||
zap.Uint64("id", ctx.ID()))
|
||||
h(ctx)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue