github.com/avicd/go-utilx@v0.1.0/logx/proxy.go (about) 1 package logx 2 3 import ( 4 "fmt" 5 "os" 6 "runtime/debug" 7 ) 8 9 type Proxy struct { 10 Level Level 11 Appender Appender 12 } 13 14 func (it *Proxy) GetLevel() Level { 15 return it.Level 16 } 17 18 func (it *Proxy) SetLevel(level Level) { 19 it.Level = level 20 } 21 22 func (it *Proxy) Debug(args ...any) { 23 if DEBUG >= it.Level { 24 it.Appender.Write(DEBUG, args...) 25 } 26 } 27 28 func (it *Proxy) Debugf(format string, args ...any) { 29 if DEBUG >= it.Level { 30 it.Appender.Write(DEBUG, fmt.Sprintf(format, args...)) 31 } 32 } 33 34 func (it *Proxy) Info(args ...any) { 35 if INFO >= it.Level { 36 it.Appender.Write(INFO, args...) 37 } 38 } 39 40 func (it *Proxy) Infof(format string, args ...any) { 41 if INFO >= it.Level { 42 it.Appender.Write(INFO, fmt.Sprintf(format, args...)) 43 } 44 } 45 46 func (it *Proxy) Warn(args ...any) { 47 if WARN >= it.Level { 48 it.Appender.Write(WARN, args...) 49 } 50 } 51 52 func (it *Proxy) Warnf(format string, args ...any) { 53 if WARN >= it.Level { 54 it.Appender.Write(WARN, fmt.Sprintf(format, args...)) 55 } 56 } 57 58 func (it *Proxy) Error(args ...any) { 59 if ERROR >= it.Level { 60 args = append(args, "\n"+string(debug.Stack())) 61 it.Appender.Write(ERROR, args...) 62 } 63 } 64 65 func (it *Proxy) Errorf(format string, args ...any) { 66 if ERROR >= it.Level { 67 var dest []any 68 dest = append(dest, fmt.Sprintf(format, args...)) 69 dest = append(dest, "\n"+string(debug.Stack())) 70 it.Appender.Write(ERROR, dest...) 71 } 72 } 73 74 func (it *Proxy) Fatal(args ...any) { 75 if FATAL >= it.Level { 76 args = append(args, "\n"+string(debug.Stack())) 77 it.Appender.Write(FATAL, args...) 78 } 79 os.Exit(1) 80 } 81 82 func (it *Proxy) Fatalf(format string, args ...any) { 83 if FATAL >= it.Level { 84 var dest []any 85 dest = append(dest, fmt.Sprintf(format, args...)) 86 dest = append(dest, "\n"+string(debug.Stack())) 87 it.Appender.Write(FATAL, dest...) 88 } 89 os.Exit(1) 90 }