mirror of
https://github.com/SajadMRjl/find-me-internet.git
synced 2026-07-13 13:56:26 +00:00
fix: add config and logger, cleanup
This commit is contained in:
31
internal/logger/logger.go
Normal file
31
internal/logger/logger.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Setup initializes the global logger based on config
|
||||
func Setup(level string) {
|
||||
var logLevel slog.Level
|
||||
|
||||
switch strings.ToUpper(level) {
|
||||
case "DEBUG":
|
||||
logLevel = slog.LevelDebug
|
||||
case "WARN":
|
||||
logLevel = slog.LevelWarn
|
||||
case "ERROR":
|
||||
logLevel = slog.LevelError
|
||||
default:
|
||||
logLevel = slog.LevelInfo
|
||||
}
|
||||
|
||||
// Create a structured text handler (easier to read than JSON in terminal)
|
||||
handler := slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
|
||||
Level: logLevel,
|
||||
})
|
||||
|
||||
logger := slog.New(handler)
|
||||
slog.SetDefault(logger)
|
||||
}
|
||||
Reference in New Issue
Block a user