package cronimport ()// DefaultLogger is used by Cron if none is specified.varDefaultLoggerLogger = PrintfLogger(log.New(os.Stdout, "cron: ", log.LstdFlags))// DiscardLogger can be used by callers to discard all log messages.varDiscardLoggerLogger = PrintfLogger(log.New(ioutil.Discard, "", 0))// Logger is the interface used in this package for logging, so that any backend// can be plugged in. It is a subset of the github.com/go-logr/logr interface.typeLoggerinterface {// Info logs routine messages about cron's operation.Info(msg string, keysAndValues ...interface{})// Error logs an error condition.Error(err error, msg string, keysAndValues ...interface{})}// PrintfLogger wraps a Printf-based logger (such as the standard library "log")// into an implementation of the Logger interface which logs errors only.func ( interface{ (string, ...interface{}) }) Logger {returnprintfLogger{, false}}// VerbosePrintfLogger wraps a Printf-based logger (such as the standard library// "log") into an implementation of the Logger interface which logs everything.func ( interface{ (string, ...interface{}) }) Logger {returnprintfLogger{, true}}type printfLogger struct { logger interface{ Printf(string, ...interface{}) } logInfo bool}func ( printfLogger) ( string, ...interface{}) {if .logInfo { = formatTimes() .logger.Printf(formatString(len()),append([]interface{}{}, ...)...) }}func ( printfLogger) ( error, string, ...interface{}) { = formatTimes() .logger.Printf(formatString(len()+2),append([]interface{}{, "error", }, ...)...)}// formatString returns a logfmt-like format string for the number of// key/values.func formatString( int) string {varstrings.Builder .WriteString("%s")if > 0 { .WriteString(", ") }for := 0; < /2; ++ {if > 0 { .WriteString(", ") } .WriteString("%v=%v") }return .String()}// formatTimes formats any time.Time values as RFC3339.func formatTimes( []interface{}) []interface{} {var []interface{}for , := range {if , := .(time.Time); { = .Format(time.RFC3339) } = append(, ) }return}
The pages are generated with Goldsv0.6.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.