github.com/sohaha/zlsgo@v1.7.13-0.20240501141223-10dd1a906f76/zlog/zlog.go (about) 1 // Package zlog provide daily log service 2 package zlog 3 4 import ( 5 "fmt" 6 "os" 7 8 "github.com/sohaha/zlsgo/zutil" 9 ) 10 11 var ( 12 log = NewZLog(os.Stderr, "", BitDefault, LogDump, true, 4) 13 osExit = func(code int) { 14 if zutil.IsDoubleClickStartUp() { 15 _, _ = fmt.Scanln() 16 } 17 os.Exit(code) 18 } 19 ) 20 21 // SetDefault set default logger 22 func SetDefault(l *Logger) { 23 log = NewZLog(l.out, l.prefix, l.flag, l.level, l.color, l.calldDepth+1) 24 } 25 26 // Deprecated: please use SetDefault 27 // GetFlags Get the tag bits 28 func GetFlags() int { 29 return log.GetFlags() 30 } 31 32 // Deprecated: please use SetDefault 33 // DisableConsoleColor DisableConsoleColor 34 func DisableConsoleColor() { 35 log.DisableConsoleColor() 36 } 37 38 // Deprecated: please use SetDefault 39 // ForceConsoleColor ForceConsoleColor 40 func ForceConsoleColor() { 41 log.ForceConsoleColor() 42 } 43 44 // Deprecated: please use SetDefault 45 // ResetFlags Setting Markup Bits 46 func ResetFlags(flag int) { 47 log.ResetFlags(flag) 48 } 49 50 // Deprecated: please use SetDefault 51 // AddFlag Set flag Tags 52 func AddFlag(flag int) { 53 log.AddFlag(flag) 54 } 55 56 // Deprecated: please use SetDefault 57 // SetPrefix Setting log header prefix 58 func SetPrefix(prefix string) { 59 log.SetPrefix(prefix) 60 } 61 62 // Deprecated: please use SetDefault 63 // SetFile Setting up log files 64 func SetFile(filepath string, archive ...bool) { 65 log.SetFile(filepath, archive...) 66 } 67 68 // Deprecated: please use SetDefault 69 // SetSaveFile SetSaveFile 70 func SetSaveFile(filepath string, archive ...bool) { 71 log.SetSaveFile(filepath, archive...) 72 } 73 74 // Deprecated: please use SetDefault 75 // SetLogLevel Setting log display level 76 func SetLogLevel(level int) { 77 log.SetLogLevel(level) 78 } 79 80 // Deprecated: please use SetDefault 81 // GetLogLevel Setting log display level 82 func GetLogLevel() int { 83 return log.level 84 } 85 86 // Debugf Debugf 87 func Debugf(format string, v ...interface{}) { 88 log.Debugf(format, v...) 89 } 90 91 // Debug Debug 92 func Debug(v ...interface{}) { 93 log.Debug(v...) 94 } 95 96 // Dump Dump 97 func Dump(v ...interface{}) { 98 if log.level < LogDump { 99 return 100 } 101 args := formatArgs(v...) 102 _, file, line, ok := callerName(1) 103 if ok { 104 names, err := argNames(file, line) 105 if err == nil { 106 args = prependArgName(names, args) 107 } 108 } 109 _ = log.outPut(LogDump, fmt.Sprintln(args...), true, log.calldDepth-1) 110 } 111 112 // Successf Successf 113 func Successf(format string, v ...interface{}) { 114 log.Successf(format, v...) 115 } 116 117 // Success Success 118 func Success(v ...interface{}) { 119 log.Success(v...) 120 } 121 122 // Infof Infof 123 func Infof(format string, v ...interface{}) { 124 log.Infof(format, v...) 125 } 126 127 // Info Info 128 func Info(v ...interface{}) { 129 log.Info(v...) 130 } 131 132 // Tipsf Tipsf 133 func Tipsf(format string, v ...interface{}) { 134 log.Tipsf(format, v...) 135 } 136 137 // Tips Tips 138 func Tips(v ...interface{}) { 139 log.Tips(v...) 140 } 141 142 // Warnf Warnf 143 func Warnf(format string, v ...interface{}) { 144 log.Warnf(format, v...) 145 } 146 147 // Warn Warn 148 func Warn(v ...interface{}) { 149 log.Warn(v...) 150 } 151 152 // Errorf Errorf 153 func Errorf(format string, v ...interface{}) { 154 log.Errorf(format, v...) 155 } 156 157 // Error Error 158 func Error(v ...interface{}) { 159 log.Error(v...) 160 } 161 162 // Printf Printf 163 func Printf(format string, v ...interface{}) { 164 log.Printf(format, v...) 165 } 166 167 // Println Println 168 func Println(v ...interface{}) { 169 log.Println(v...) 170 } 171 172 // Fatalf Fatalf 173 func Fatalf(format string, v ...interface{}) { 174 log.Fatalf(format, v...) 175 } 176 177 // Fatal Fatal 178 func Fatal(v ...interface{}) { 179 log.Fatal(v...) 180 } 181 182 // Panicf Panicf 183 func Panicf(format string, v ...interface{}) { 184 log.Panicf(format, v...) 185 } 186 187 // Panic panic 188 func Panic(v ...interface{}) { 189 log.Panic(v...) 190 } 191 192 // Track Track 193 func Track(v string, i ...int) { 194 log.Track(v, i...) 195 } 196 197 // Stack Stack 198 func Stack(v interface{}) { 199 log.Stack(v) 200 } 201 202 // Discard Discard 203 func Discard() { 204 log.Discard() 205 }