MCPcopy Index your code
hub / github.com/DoNewsCode/core / WithLogging

Function WithLogging

cron/options.go:53–74  ·  view source on GitHub ↗

WithLogging returns a new Universal job that will log.

(logger log.Logger)

Source from the content-addressed store, hash-verified

51
52// WithLogging returns a new Universal job that will log.
53func WithLogging(logger log.Logger) JobOption {
54 return func(descriptor *JobDescriptor) {
55 innerRun := descriptor.Run
56 descriptor.Run = func(ctx context.Context) error {
57 due := GetCurrentSchedule(ctx)
58 delayed := time.Since(due)
59 l := logging.WithContext(logger, ctx)
60 if delayed > time.Second {
61 l = log.With(l, "delayed", delayed)
62 }
63 l = log.With(l, "job", descriptor.Name, "schedule", descriptor.RawSpec)
64 l.Log("msg", logging.Sprintf("job %s started", descriptor.Name))
65 err := innerRun(ctx)
66 if err != nil {
67 l.Log("msg", logging.Sprintf("job %s finished with error: %s", descriptor.Name, err))
68 return err
69 }
70 l.Log("msg", logging.Sprintf("job %s completed", descriptor.Name))
71 return nil
72 }
73 }
74}
75
76// WithTracing returns a new Universal job that will trace.
77func WithTracing(tracer opentracing.Tracer) JobOption {

Callers 2

cronServeMethod · 0.92
TestJobOptionFunction · 0.85

Calls 5

WithContextFunction · 0.92
SprintfFunction · 0.92
GetCurrentScheduleFunction · 0.85
LogMethod · 0.80
WithMethod · 0.45

Tested by 1

TestJobOptionFunction · 0.68