Skip to content

Commit 4f2060c

Browse files
committed
Add utility functions for colored logging messages
1 parent b32e0ac commit 4f2060c

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

arch-sandbox

16 Bytes
Binary file not shown.

utils/colors.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package utils
2+
3+
import (
4+
"fmt"
5+
"log"
6+
)
7+
8+
// ANSI color codes
9+
const (
10+
ColorReset = "\033[0m"
11+
ColorRed = "\033[31m"
12+
ColorGreen = "\033[32m"
13+
ColorYellow = "\033[33m"
14+
ColorCyan = "\033[36m"
15+
)
16+
17+
// Info prints a formatted informational message in cyan.
18+
func Info(format string, a ...interface{}) {
19+
fmt.Printf(ColorCyan+"[INFO] "+ColorReset+format+"\n", a...)
20+
}
21+
22+
// Success prints a formatted success message in green.
23+
func Success(format string, a ...interface{}) {
24+
fmt.Printf(ColorGreen+"[SUCCESS] "+ColorReset+format+"\n", a...)
25+
}
26+
27+
// Warn prints a formatted warning message in yellow.
28+
func Warn(format string, a ...interface{}) {
29+
fmt.Printf(ColorYellow+"[WARN] "+ColorReset+format+"\n", a...)
30+
}
31+
32+
// Fatal prints a formatted fatal error message in red and exits.
33+
func Fatal(format string, a ...interface{}) {
34+
// We use log.Fatalf to ensure the timestamp and exit behavior are consistent.
35+
log.Fatalf(ColorRed+"[FATAL] "+ColorReset+format, a...)
36+
}

0 commit comments

Comments
 (0)