4a332b566020b067a0e14b4769358be226f456e5.svn-base 960 B

123456789101112131415161718192021222324252627282930313233343536
  1. package handling
  2. import (
  3. "time"
  4. "github.com/go-kit/kit/log"
  5. shipping "github.com/longjoy/micro-go-course/section19/cargo/model"
  6. )
  7. type loggingService struct {
  8. logger log.Logger
  9. next Service
  10. }
  11. // NewLoggingService returns a new instance of a logging Service.
  12. func NewLoggingService(logger log.Logger, s Service) Service {
  13. return &loggingService{logger, s}
  14. }
  15. func (s *loggingService) RegisterHandlingEvent(completed time.Time, id shipping.TrackingID, voyageNumber shipping.VoyageNumber,
  16. unLocode shipping.UNLocode, eventType shipping.HandlingEventType) (res bool, err error) {
  17. defer func(begin time.Time) {
  18. s.logger.Log(
  19. "method", "register_incident",
  20. "tracking_id", id,
  21. "location", unLocode,
  22. "voyage", voyageNumber,
  23. "event_type", eventType,
  24. "completion_time", completed,
  25. "took", time.Since(begin),
  26. "err", err,
  27. )
  28. }(time.Now())
  29. return s.next.RegisterHandlingEvent(completed, id, voyageNumber, unLocode, eventType)
  30. }