github.com/aergoio/aergo@v1.3.1/consensus/impl/raftv2/raftlogger.go (about) 1 package raftv2 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/aergoio/aergo-lib/log" 8 ) 9 10 // Logger is a logging unit. It controls the flow of messages to a given 11 // (swappable) backend. 12 type RaftLogger struct { 13 logger *log.Logger 14 } 15 16 func NewRaftLogger(logger *log.Logger) *RaftLogger { 17 if logger == nil { 18 panic("base logger of raft is nil") 19 return nil 20 } 21 22 return &RaftLogger{logger: logger} 23 } 24 func (l RaftLogger) Fatal(args ...interface{}) { 25 s := fmt.Sprint(args...) 26 logger.Fatal().Msgf("%s", s) 27 } 28 29 func (l *RaftLogger) Fatalf(format string, args ...interface{}) { 30 logger.Fatal().Msgf(format, args...) 31 } 32 33 func (l *RaftLogger) Panic(args ...interface{}) { 34 s := fmt.Sprint(args...) 35 logger.Panic().Msgf("%s", s) 36 } 37 38 func (l *RaftLogger) Panicf(format string, args ...interface{}) { 39 logger.Panic().Msgf(format, args...) 40 } 41 42 func (l *RaftLogger) Error(args ...interface{}) { 43 logger.Error().Msgf(defaultArgsFormat(len(args)), args...) 44 } 45 46 func (l *RaftLogger) Errorf(format string, args ...interface{}) { 47 logger.Error().Msgf(format, args...) 48 } 49 50 func (l *RaftLogger) Warning(args ...interface{}) { 51 logger.Warn().Msgf(defaultArgsFormat(len(args)), args...) 52 } 53 54 func (l *RaftLogger) Warningf(format string, args ...interface{}) { 55 logger.Warn().Msgf(format, args...) 56 } 57 58 func (l *RaftLogger) Info(args ...interface{}) { 59 logger.Info().Msgf(defaultArgsFormat(len(args)), args...) 60 } 61 62 func (l *RaftLogger) Infof(format string, args ...interface{}) { 63 logger.Info().Msgf(format, args...) 64 } 65 66 func (l *RaftLogger) Debug(args ...interface{}) { 67 logger.Debug().Msgf(defaultArgsFormat(len(args)), args...) 68 } 69 70 func (l *RaftLogger) Debugf(format string, args ...interface{}) { 71 logger.Debug().Msgf(format, args...) 72 } 73 74 func defaultArgsFormat(argc int) string { 75 f := strings.Repeat("%s ", argc) 76 if argc > 0 { 77 f = f[:len(f)-1] 78 } 79 return f 80 }