re-write with std usage of net/http
This commit is contained in:
parent
c107d94b11
commit
81bc046237
10 changed files with 419 additions and 97 deletions
41
logger/logger.go
Normal file
41
logger/logger.go
Normal file
|
@ -0,0 +1,41 @@
|
|||
package logger
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ANSI colors
|
||||
const (
|
||||
colorReset = "\033[0m"
|
||||
colorRed = "\033[31m"
|
||||
colorYellow = "\033[33m"
|
||||
colorCyan = "\033[36m"
|
||||
colorWhite = "\033[97m"
|
||||
)
|
||||
|
||||
// Log levels
|
||||
const (
|
||||
LevelInfo = "INFO"
|
||||
LevelWarn = "WARN"
|
||||
LevelError = "ERROR"
|
||||
LevelFatal = "FATAL"
|
||||
)
|
||||
|
||||
func logMessage(level, color, msg string, args ...any) {
|
||||
timestamp := time.Now().Format("2006-01-02 15:04:05")
|
||||
formatted := fmt.Sprintf(msg, args...)
|
||||
output := fmt.Sprintf("[%s] %s[%s]%s %s\n", timestamp, color, level, colorReset, formatted)
|
||||
fmt.Print(output)
|
||||
|
||||
if level == LevelFatal {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// Public logging functions
|
||||
func Info(msg string, args ...any) { logMessage(LevelInfo, colorCyan, msg, args...) }
|
||||
func Warn(msg string, args ...any) { logMessage(LevelWarn, colorYellow, msg, args...) }
|
||||
func Error(msg string, args ...any) { logMessage(LevelError, colorRed, msg, args...) }
|
||||
func Fatal(msg string, args ...any) { logMessage(LevelFatal, colorRed, msg, args...) }
|
Loading…
Add table
Add a link
Reference in a new issue