-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogging.go
30 lines (25 loc) · 817 Bytes
/
logging.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package goco2
import (
"context"
"log"
"time"
)
// LoggingService implements basic middleware logging for the microservice
type LoggingService struct {
next Service
}
func NewLoggingService(next Service) Service {
return &LoggingService{next: next}
}
func (s *LoggingService) GetCO2Saving(ctx context.Context) (saving *CO2Saving, err error) {
defer func(start time.Time) {
log.Printf("CO2 Saving: %+v, error: %v, took: %v\n", saving, err, time.Since(start))
}(time.Now())
return s.next.GetCO2Saving(ctx)
}
func (s *LoggingService) AddIntervention(ctx context.Context, intervention Intervention) (err error) {
defer func(start time.Time) {
log.Printf("Intervention: %+v, error: %v, took: %v\n", intervention, err, time.Since(start))
}(time.Now())
return s.next.AddIntervention(ctx, intervention)
}