Gin: pull response time from gin

Created on 30 Jan 2019  路  2Comments  路  Source: gin-gonic/gin

branch = "master"
digest = "1:6375f542808927c64c4938b160697a53b597f3db29cd0cf7faa576b8dd251155"
name = "github.com/gin-gonic/gin"
revision = "500ebd9ea866c57427aeaddc31f374adedd4084b"

go version:
1.11.4

I cannot seem to find any way to pull the same response time that gin outputs to stdout (in microseconds). I am talking about this (174.138碌s)
image
I am currently using this snnippet in middleware:
start := time.Now()
c.Next()
end := time.Now().Sub(start)
But It does not match to whatever the gin prints to stdout.

I have searched both repo, google and package files through IDE tools but cannot find any built in way to do this.
Could you confirm that this feature does not exist?
Or point me to the direction how could I calculate exactly the same or closely matching time?

Can it be done without gin.Logger() ?
I use custom logger and I just want latency value.
Thanks

Most helpful comment

gin.Logger does not serve the function you want.

Instead of it, gin.LoggerWithFormatter, which is implemented in master branch or future release v1.4, would live up to your expectations.

Latency field in LogFormatterParams, passed to arguments by LogFormatter interface function, equals to the response time that gin outputs to stdout.

All 2 comments

gin.Logger does not serve the function you want.

Instead of it, gin.LoggerWithFormatter, which is implemented in master branch or future release v1.4, would live up to your expectations.

Latency field in LogFormatterParams, passed to arguments by LogFormatter interface function, equals to the response time that gin outputs to stdout.

as @sairoutine said, thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gplume picture gplume  路  3Comments

mastrolinux picture mastrolinux  路  3Comments

nxvl picture nxvl  路  3Comments

mdnight picture mdnight  路  3Comments

frederikhors picture frederikhors  路  3Comments