Skip to content

Commit cd777af

Browse files
committed
update logging
1 parent 9a4fc67 commit cd777af

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

logs/logs.go

+11-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ import (
77
"os"
88
)
99

10+
const (
11+
ColorReset = "\033[0m"
12+
ColorRed = "\033[31m"
13+
ColorGreen = "\033[32m"
14+
ColorYellow = "\033[33m"
15+
)
16+
1017
var c *log.Logger
1118

1219
func init() {
@@ -24,21 +31,21 @@ func print(s string) {
2431

2532
// Info ...
2633
func Info(format string, args ...any) {
27-
print("INFO: " + fmt.Sprintf(format, args...))
34+
print(fmt.Sprintf("%sINFO%s: %s", ColorGreen, ColorReset, fmt.Sprintf(format, args...)))
2835
}
2936

3037
// Warn ...
3138
func Warn(format string, args ...any) {
32-
print("WARN: " + fmt.Sprintf(format, args...))
39+
print(fmt.Sprintf("%sWARN%s: %s", ColorYellow, ColorReset, fmt.Sprintf(format, args...)))
3340
}
3441

3542
// Error ...
3643
func Error(format string, args ...any) {
37-
print("ERROR: " + fmt.Sprintf(format, args...))
44+
print(fmt.Sprintf("%sERROR%s: %s", ColorRed, ColorReset, fmt.Sprintf(format, args...)))
3845
}
3946

4047
// Fatal ...
4148
func Fatal(format string, args ...any) {
42-
print("FATAL: " + fmt.Sprintf(format, args...))
49+
print(fmt.Sprintf("%sFATAL%s: %s", ColorRed, ColorReset, fmt.Sprintf(format, args...)))
4350
os.Exit(1)
4451
}

0 commit comments

Comments
 (0)