1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| package logger
import ( "fmt" "time" )
const ( _DEBUG_COLOR int = 30 _INFO_COLOR int = 32 _WARN_COLOR int = 33 _ERROR_COLOR int = 31 )
func getCurrentTime() string { now := time.Now() year, month, day := now.Date() hour, minite, second := now.Clock() dateTime := fmt.Sprintf("%d-%d-%d %d:%d:%d", year, month, day, hour, minite, second) return dateTime }
func Debug(msg string, params ...any) { printLog(msg, _DEBUG_COLOR, params...) }
func Info(msg string, params ...any) { printLog(msg, _INFO_COLOR, params...) }
func Warn(msg string, params ...any) { printLog(msg, _WARN_COLOR, params...) }
func Error(msg string, params ...any) { printLog(msg, _ERROR_COLOR, params...) }
func printLog(msg string, color int, params ...any) { if len(params) != 0 { msg = fmt.Sprintf(msg, params...) } currentTime := getCurrentTime() fmt.Printf("[%s] \033[%dm%s\033[0m\n", currentTime, color, msg) }
|