mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-26 17:49:15 +01:00
- Replaced all instances of apex/log with a structured logger interface in various services, including Api, Server, Config, and others, to enhance logging consistency and context. - Updated logging calls to utilize the new logger methods, improving error tracking and service monitoring. - Added logger initialization in services and controllers to ensure proper logging setup. - Improved error handling and logging messages for better clarity during service operations. - Removed unused apex/log imports and cleaned up related code for better maintainability.
37 lines
796 B
Go
37 lines
796 B
Go
package schedule
|
|
|
|
import (
|
|
"github.com/crawlab-team/crawlab/core/interfaces"
|
|
"github.com/crawlab-team/crawlab/core/utils"
|
|
"github.com/robfig/cron/v3"
|
|
"strings"
|
|
)
|
|
|
|
type CronLogger struct {
|
|
interfaces.Logger
|
|
}
|
|
|
|
func (l *CronLogger) Info(msg string, keysAndValues ...interface{}) {
|
|
p := l.getPlaceholder(len(keysAndValues))
|
|
l.Infof("cron: %s %s", msg, p)
|
|
}
|
|
|
|
func (l *CronLogger) Error(err error, msg string, keysAndValues ...interface{}) {
|
|
p := l.getPlaceholder(len(keysAndValues))
|
|
l.Errorf("cron: %s %v %s", msg, err, p)
|
|
}
|
|
|
|
func (l *CronLogger) getPlaceholder(n int) (s string) {
|
|
var arr []string
|
|
for i := 0; i < n; i++ {
|
|
arr = append(arr, "%v")
|
|
}
|
|
return strings.Join(arr, " ")
|
|
}
|
|
|
|
func NewCronLogger() cron.Logger {
|
|
return &CronLogger{
|
|
Logger: utils.NewLogger("CronLogger"),
|
|
}
|
|
}
|