-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add endpoint logging middleware to log total execution time of an end…
…point
- Loading branch information
1 parent
40ef9a0
commit 9cabf64
Showing
4 changed files
with
26 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package middleware | ||
|
||
import ( | ||
"github.com/lukasjarosch/godin/pkg/log" | ||
"github.com/go-kit/kit/endpoint" | ||
"context" | ||
"time" | ||
) | ||
|
||
func Logging(logger log.Logger, endpointName string) endpoint.Middleware { | ||
return func(next endpoint.Endpoint) endpoint.Endpoint { | ||
return func(ctx context.Context, request interface{}) (response interface{}, err error) { | ||
defer func(begin time.Time) { | ||
logger.Info("", "endpoint", endpointName, "took", time.Since(begin)) | ||
}(time.Now()) | ||
|
||
return next(ctx, request) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters