package logging import ( "context" "time" "git.espin.casa/albert/cml04-gdm-int/internal/service" "git.espin.casa/albert/cml04-gdm-int/pkg/api" "git.espin.casa/albert/logger" ) type Logging struct { log logger.LoggerAdapter next service.IService } // BdRollData implements service.IService. func (svc *Logging) BdRollData(ctx context.Context, req *api.BdRollDataReq) (res *api.BdRollDataRes, err error) { defer func(start time.Time) { logFields := logger.LogFields{ "took": time.Since(start), "sender": req.GetSender(), "roll_id": req.GetRollId(), } if err != nil { svc.log.Error("Break Down Roll Data failed", err, logFields) } else { svc.log.Info("Break Down Roll Data success", logFields) } }(time.Now()) return svc.next.BdRollData(ctx, req) } // EdRollData implements service.IService. func (svc *Logging) EdRollData(ctx context.Context, req *api.EdRollDataReq) (res *api.EdRollDataRes, err error) { defer func(start time.Time) { logFields := logger.LogFields{ "took": time.Since(start), "sender": req.GetSender(), "roll_id": req.GetRollId(), } if err != nil { svc.log.Error("Edge Roll Data failed", err, logFields) } else { svc.log.Info("Edge Roll Data success", logFields) } }(time.Now()) return svc.next.EdRollData(ctx, req) } // UfRollData implements service.IService. func (svc *Logging) UfRollData(ctx context.Context, req *api.UfRollDataReq) (res *api.UfRollDataRes, err error) { defer func(start time.Time) { logFields := logger.LogFields{ "took": time.Since(start), "sender": req.GetSender(), "roll_id": req.GetRollId(), } if err != nil { svc.log.Error("Universal Finishing Roll Data failed", err, logFields) } else { svc.log.Info("Universal Finishing Roll Data success", logFields) } }(time.Now()) return svc.next.UfRollData(ctx, req) } // UrRollData implements service.IService. func (svc *Logging) UrRollData(ctx context.Context, req *api.UrRollDataReq) (res *api.UrRollDataRes, err error) { defer func(start time.Time) { logFields := logger.LogFields{ "took": time.Since(start), "sender": req.GetSender(), "roll_id": req.GetRollId(), } if err != nil { svc.log.Error("Universal Rolling Roll Data failed", err, logFields) } else { svc.log.Info("Universal Rolling Roll Data success", logFields) } }(time.Now()) return svc.next.UrRollData(ctx, req) } func NewLoggingService(log logger.LoggerAdapter, next service.IService) service.IService { return &Logging{log, next} }