github.com/cranelv/ethereum_mpc@v0.0.0-20191031014521-23aeb1415092/mpcService/protocol/logger.go (about) 1 package protocol 2 3 import ( 4 "fmt" 5 "github.com/ethereum/go-ethereum/log" 6 "sync" 7 "strings" 8 ) 9 type TestLogger struct { 10 mu sync.Mutex 11 LogMap map[string]int 12 } 13 func (lg *TestLogger)Error(format string, ctx ...interface{}){ 14 txt := fmt.Sprintf(format,ctx...) 15 // log.Error(txt) 16 lg.mu.Lock() 17 txtAry := strings.Split(txt,",") 18 for _,tx := range txtAry{ 19 item := strings.Trim(tx, " ") 20 lg.LogMap[item]++ 21 } 22 defer lg.mu.Unlock() 23 } 24 var TLog = &TestLogger{ 25 LogMap:make(map[string]int), 26 } 27 type MpcLogger struct { 28 Log bool 29 } 30 func (pl *MpcLogger)Debug(args... interface{}){ 31 if pl.Log{ 32 log.Debug(args[0].(string),args[1:]...) 33 } 34 } 35 func (pl *MpcLogger)Debugln(args ...interface{}){ 36 if pl.Log{ 37 log.Debug(args[0].(string),args[1:]...) 38 } 39 } 40 func (pl *MpcLogger)Debugf(msg string, args... interface{}){ 41 if pl.Log{ 42 log.Debug(fmt.Sprintf(msg,args...)) 43 } 44 } 45 46 func (pl *MpcLogger)Info(args ...interface{}){ 47 if pl.Log{ 48 log.Info(args[0].(string),args[1:]...) 49 } 50 } 51 func (pl *MpcLogger)Infoln(args ...interface{}){ 52 if pl.Log{ 53 log.Info(args[0].(string),args[1:]...) 54 } 55 } 56 func (pl *MpcLogger)Infof(msg string, args ...interface{}){ 57 if pl.Log{ 58 log.Info(fmt.Sprintf(msg,args...)) 59 } 60 } 61 62 func (pl *MpcLogger)Warn(args ...interface{}){ 63 if pl.Log{ 64 log.Warn(args[0].(string),args[1:]...) 65 } 66 } 67 func (pl *MpcLogger)Warnln(args ...interface{}){ 68 if pl.Log{ 69 log.Warn(args[0].(string),args[1:]...) 70 } 71 } 72 func (pl *MpcLogger)Warnf(msg string, args ...interface{}){ 73 if pl.Log{ 74 log.Warn(fmt.Sprintf(msg,args...)) 75 } 76 } 77 78 func (pl *MpcLogger)Error(args ...interface{}){ 79 if pl.Log{ 80 log.Error(args[0].(string),args[1:]...) 81 } 82 } 83 func (pl *MpcLogger)Errorln(args ...interface{}){ 84 if pl.Log{ 85 log.Error(args[0].(string),args[1:]...) 86 } 87 } 88 func (pl *MpcLogger)Errorf(msg string, args ...interface{}){ 89 if pl.Log{ 90 log.Error(fmt.Sprintf(msg,args...)) 91 } 92 } 93 94 func (pl *MpcLogger)Fatal(args ...interface{}){ 95 if pl.Log{ 96 log.Crit(args[0].(string),args[1:]...) 97 } 98 } 99 func (pl *MpcLogger)Fatalln(args ...interface{}){ 100 if pl.Log{ 101 log.Crit(args[0].(string),args[1:]...) 102 } 103 } 104 func (pl *MpcLogger)Fatalf(msg string, args ...interface{}){ 105 if pl.Log{ 106 log.Crit(fmt.Sprintf(msg,args...)) 107 } 108 } 109 110 func (pl *MpcLogger)SetFormat(string) error{ 111 return nil 112 } 113 func (pl *MpcLogger)SetLevel(string) error{ 114 return nil 115 } 116