logging.go 532 B

123456789101112131415161718192021222324
  1. package tracking
  2. import (
  3. "time"
  4. "github.com/go-kit/kit/log"
  5. )
  6. type loggingService struct {
  7. logger log.Logger
  8. next Service
  9. }
  10. // NewLoggingService returns a new instance of a logging Service.
  11. func NewLoggingService(logger log.Logger, s Service) Service {
  12. return &loggingService{logger, s}
  13. }
  14. func (s *loggingService) Track(id string) (c Cargo, err error) {
  15. defer func(begin time.Time) {
  16. s.logger.Log("method", "track", "tracking_id", id, "took", time.Since(begin), "err", err)
  17. }(time.Now())
  18. return s.next.Track(id)
  19. }