libi / dcron

轻量分布式定时任务库 a lightweight distributed job scheduler library
MIT License
422 stars 73 forks source link

无法打印输出cron的全量日志 #68

Closed ly-wjj closed 8 months ago

ly-wjj commented 8 months ago

问题说明: 当设置的标准日志输出,在addFunc中的func想要日志输出,实际上并没有输出日志。设置WithPrintLogInfo只是打印了dcron的日志,cron的日志还是无法打印。 问题原因: 默认设置日志格式的时候

// WithLogger both set dcron and cron logger.
func WithLogger(logger interface{ Printf(string, ...interface{}) }) Option {
    return func(dcron *Dcron) {
        //set dcron logger
        dcron.logger = logger
        //set cron logger,这里设置的是标准日志输出,很多信息无法打印
        f := cron.WithLogger(cron.PrintfLogger(logger))
        dcron.crOptions = append(dcron.crOptions, f)
    }
}
// PrintfLogger wraps a Printf-based logger (such as the standard library "log")
// into an implementation of the Logger interface which logs errors only.
func PrintfLogger(l interface{ Printf(string, ...interface{}) }) Logger {
    return printfLogger{l, false}
}

// VerbosePrintfLogger wraps a Printf-based logger (such as the standard library
// "log") into an implementation of the Logger interface which logs everything.
func VerbosePrintfLogger(l interface{ Printf(string, ...interface{}) }) Logger {
    return printfLogger{l, true}
}

建议设置dcron.loginfo设置为true的时候,则cron改成,f := cron.VerbosePrintfLogger(cron.PrintfLogger(logger)) ?

dxyinme commented 8 months ago

感谢提交issue, 会跟进这个问题。