Files
crawlab/core/schedule/logger.go
2024-06-14 16:37:48 +08:00

36 lines
765 B
Go

package schedule
import (
"fmt"
"github.com/apex/log"
"github.com/crawlab-team/crawlab/trace"
"github.com/robfig/cron/v3"
"strings"
)
type Logger struct {
}
func (l *Logger) Info(msg string, keysAndValues ...interface{}) {
p := l.getPlaceholder(len(keysAndValues))
log.Infof(fmt.Sprintf("cron: %s %s", msg, p), keysAndValues...)
}
func (l *Logger) Error(err error, msg string, keysAndValues ...interface{}) {
p := l.getPlaceholder(len(keysAndValues))
log.Errorf(fmt.Sprintf("cron: %s %s", msg, p), keysAndValues...)
trace.PrintError(err)
}
func (l *Logger) getPlaceholder(n int) (s string) {
var arr []string
for i := 0; i < n; i++ {
arr = append(arr, "%v")
}
return strings.Join(arr, " ")
}
func NewLogger() cron.Logger {
return &Logger{}
}