feat: color log, upx release; format: debug log
This commit is contained in:
43
internal/log/log.go
Normal file
43
internal/log/log.go
Normal file
@ -0,0 +1,43 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/fatih/color"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
red = color.New(color.FgRed)
|
||||
green = color.New(color.FgGreen)
|
||||
yellow = color.New(color.FgYellow)
|
||||
|
||||
locker = &sync.Mutex{}
|
||||
|
||||
timeFormat = "06/01/02T15:04:05"
|
||||
)
|
||||
|
||||
func Info(msg string, data ...any) {
|
||||
buf := &bytes.Buffer{}
|
||||
_, _ = green.Fprint(buf, "Info ")
|
||||
_, _ = fmt.Fprintf(buf, "| %s | ", time.Now().Format(timeFormat))
|
||||
_, _ = fmt.Fprintf(buf, msg, data...)
|
||||
fmt.Println(buf.String())
|
||||
}
|
||||
|
||||
func Warn(msg string, data ...any) {
|
||||
buf := &bytes.Buffer{}
|
||||
_, _ = yellow.Fprint(buf, "Warn ")
|
||||
_, _ = fmt.Fprintf(buf, "| %s | ", time.Now().Format(timeFormat))
|
||||
_, _ = fmt.Fprintf(buf, msg, data...)
|
||||
fmt.Println(buf.String())
|
||||
}
|
||||
|
||||
func Error(msg string, data ...any) {
|
||||
buf := &bytes.Buffer{}
|
||||
_, _ = red.Fprint(buf, "Error ")
|
||||
_, _ = fmt.Fprintf(buf, "| %s | ", time.Now().Format(timeFormat))
|
||||
_, _ = fmt.Fprintf(buf, msg, data...)
|
||||
fmt.Println(buf.String())
|
||||
}
|
Reference in New Issue
Block a user