2
0
mirror of https://github.com/hibiken/asynq.git synced 2024-12-25 07:12:17 +08:00

Change default log level to info

This commit is contained in:
Ken Hibino 2020-05-11 06:55:04 -07:00
parent 0faf97f146
commit ae942c93e5

View File

@ -115,7 +115,7 @@ type Config struct {
// LogLevel specifies the minimum log level to enable. // LogLevel specifies the minimum log level to enable.
// //
// If unset, DebugLevel is used by default. // If unset, InfoLevel is used by default.
LogLevel LogLevel LogLevel LogLevel
// ShutdownTimeout specifies the duration to wait to let workers finish their tasks // ShutdownTimeout specifies the duration to wait to let workers finish their tasks
@ -164,9 +164,12 @@ type Logger interface {
type LogLevel int32 type LogLevel int32
const ( const (
// Note: reserving value zero to differentiate unspecified case.
level_unspecified LogLevel = iota
// DebugLevel is the lowest level of logging. // DebugLevel is the lowest level of logging.
// Debug logs are intended for debugging and development purposes. // Debug logs are intended for debugging and development purposes.
DebugLevel LogLevel = iota DebugLevel
// InfoLevel is used for general informational log messages. // InfoLevel is used for general informational log messages.
InfoLevel InfoLevel
@ -220,6 +223,22 @@ func (l *LogLevel) Set(val string) error {
return nil return nil
} }
func toInternalLogLevel(l LogLevel) log.Level {
switch l {
case DebugLevel:
return log.DebugLevel
case InfoLevel:
return log.InfoLevel
case WarnLevel:
return log.WarnLevel
case ErrorLevel:
return log.ErrorLevel
case FatalLevel:
return log.FatalLevel
}
panic(fmt.Sprintf("asynq: unexpected log level: %v", l))
}
// Formula taken from https://github.com/mperham/sidekiq. // Formula taken from https://github.com/mperham/sidekiq.
func defaultDelayFunc(n int, e error, t *Task) time.Duration { func defaultDelayFunc(n int, e error, t *Task) time.Duration {
r := rand.New(rand.NewSource(time.Now().UnixNano())) r := rand.New(rand.NewSource(time.Now().UnixNano()))
@ -258,7 +277,11 @@ func NewServer(r RedisConnOpt, cfg Config) *Server {
shutdownTimeout = defaultShutdownTimeout shutdownTimeout = defaultShutdownTimeout
} }
logger := log.NewLogger(cfg.Logger) logger := log.NewLogger(cfg.Logger)
logger.SetLevel(log.Level(cfg.LogLevel)) loglevel := cfg.LogLevel
if loglevel == level_unspecified {
loglevel = InfoLevel
}
logger.SetLevel(toInternalLogLevel(loglevel))
host, err := os.Hostname() host, err := os.Hostname()
if err != nil { if err != nil {