[GH-ISSUE #459] [FEATURE REQUEST] Periodic Tasks support customize cron logger #2238

Closed
opened 2026-03-15 19:48:29 +03:00 by kerem · 4 comments
Owner

Originally created by @yxlimo on GitHub (May 10, 2022).
Original GitHub issue: https://github.com/hibiken/asynq/issues/459

Originally assigned to: @hibiken on GitHub.

i want to customize cron logger to get more info, but i can't do it with scheduler

return &Scheduler{
  cron:       cron.New(cron.WithLocation(loc)),
}

maybe we can add an option for schedulerOpts like

struct {
    CronLogger cron.Logger
    Logger Logger
    LogLevel LogLevel
}

or just use asynq logger wrapper, seems little strange, and it need to do many things to handle edge case.

type cronLoggerWrapper struct {
       logger Logger
}

func (l *cronLoggerWrapper) Info(msg string, keysAndValues ...interface{}) {
       l.logger.Info(msg, )
}

WDYT?

Originally created by @yxlimo on GitHub (May 10, 2022). Original GitHub issue: https://github.com/hibiken/asynq/issues/459 Originally assigned to: @hibiken on GitHub. i want to customize cron logger to get more info, but i can't do it with scheduler ``` return &Scheduler{ cron: cron.New(cron.WithLocation(loc)), } ``` maybe we can add an option for schedulerOpts like ``` struct { CronLogger cron.Logger Logger Logger LogLevel LogLevel } ``` or just use asynq logger wrapper, seems little strange, and it need to do many things to handle edge case. ``` type cronLoggerWrapper struct { logger Logger } func (l *cronLoggerWrapper) Info(msg string, keysAndValues ...interface{}) { l.logger.Info(msg, ) } ``` WDYT?
kerem 2026-03-15 19:48:29 +03:00
Author
Owner

@hibiken commented on GitHub (May 10, 2022):

@yxlimo Thank you for opening an issue!
What kind of logs do you need?

<!-- gh-comment-id:1122349274 --> @hibiken commented on GitHub (May 10, 2022): @yxlimo Thank you for opening an issue! What kind of logs do you need?
Author
Owner

@yxlimo commented on GitHub (May 11, 2022):

@yxlimo Thank you for opening an issue! What kind of logs do you need?

thank you for reply,i need logs like this

  • every time cronjob started
  • enqueue task success or failed
<!-- gh-comment-id:1123141409 --> @yxlimo commented on GitHub (May 11, 2022): > @yxlimo Thank you for opening an issue! What kind of logs do you need? thank you for reply,i need logs like this - every time cronjob started - enqueue task success or failed
Author
Owner

@hibiken commented on GitHub (May 12, 2022):

every time cronjob started

You can do this within your Handler code. If it's shared between multiple task types, I'd recommend using MiddlewareFunc to have that applied to multiple tasks. See this wiki page for examples.

enqueue task success or failed

Currently, you can provide SchedulerOpts.EnqueueErrorHandler but there's an open feature request to add callbacks to both before and after the enqueue event #456; And probably this feature will be available pretty soon

<!-- gh-comment-id:1125200454 --> @hibiken commented on GitHub (May 12, 2022): > every time cronjob started You can do this within your `Handler` code. If it's shared between multiple task types, I'd recommend using `MiddlewareFunc` to have that applied to multiple tasks. See [this wiki page](https://github.com/hibiken/asynq/wiki/Handler-Deep-Dive#using-middleware) for examples. > enqueue task success or failed Currently, you can provide [`SchedulerOpts.EnqueueErrorHandler`](https://pkg.go.dev/github.com/hibiken/asynq#SchedulerOpts.EnqueueErrorHandler) but there's an open feature request to add callbacks to both before and after the enqueue event #456; And probably this feature will be available pretty soon
Author
Owner

@hibiken commented on GitHub (Jun 4, 2022):

Closing this since it can be achieved using pre and post enqueue callbacks added in #476

<!-- gh-comment-id:1146676272 --> @hibiken commented on GitHub (Jun 4, 2022): Closing this since it can be achieved using pre and post enqueue callbacks added in #476
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/asynq#2238
No description provided.