6 "github.com/go-kit/kit/log"
8 "github.com/go-kit/kit/examples/shipping/cargo"
9 "github.com/go-kit/kit/examples/shipping/location"
12 type loggingService struct {
17 // NewLoggingService returns a new instance of a logging Service.
18 func NewLoggingService(logger log.Logger, s Service) Service {
19 return &loggingService{logger, s}
22 func (s *loggingService) BookNewCargo(origin location.UNLocode, destination location.UNLocode, deadline time.Time) (id cargo.TrackingID, err error) {
23 defer func(begin time.Time) {
27 "destination", destination,
28 "arrival_deadline", deadline,
29 "took", time.Since(begin),
33 return s.Service.BookNewCargo(origin, destination, deadline)
36 func (s *loggingService) LoadCargo(id cargo.TrackingID) (c Cargo, err error) {
37 defer func(begin time.Time) {
41 "took", time.Since(begin),
45 return s.Service.LoadCargo(id)
48 func (s *loggingService) RequestPossibleRoutesForCargo(id cargo.TrackingID) []cargo.Itinerary {
49 defer func(begin time.Time) {
51 "method", "request_routes",
53 "took", time.Since(begin),
56 return s.Service.RequestPossibleRoutesForCargo(id)
59 func (s *loggingService) AssignCargoToRoute(id cargo.TrackingID, itinerary cargo.Itinerary) (err error) {
60 defer func(begin time.Time) {
62 "method", "assign_to_route",
64 "took", time.Since(begin),
68 return s.Service.AssignCargoToRoute(id, itinerary)
71 func (s *loggingService) ChangeDestination(id cargo.TrackingID, l location.UNLocode) (err error) {
72 defer func(begin time.Time) {
74 "method", "change_destination",
77 "took", time.Since(begin),
81 return s.Service.ChangeDestination(id, l)
84 func (s *loggingService) Cargos() []Cargo {
85 defer func(begin time.Time) {
87 "method", "list_cargos",
88 "took", time.Since(begin),
91 return s.Service.Cargos()
94 func (s *loggingService) Locations() []Location {
95 defer func(begin time.Time) {
97 "method", "list_locations",
98 "took", time.Since(begin),
101 return s.Service.Locations()