BAMS initial project structure

This commit is contained in:
2025-12-23 18:34:39 +00:00
parent e1df870f98
commit 861e0f65c3
24 changed files with 2495 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
package logger
import (
"log"
"os"
)
type Logger struct {
level string
log *log.Logger
}
func New(level string) *Logger {
return &Logger{
level: level,
log: log.New(os.Stdout, "[BAMS] ", log.LstdFlags|log.Lshortfile),
}
}
func (l *Logger) Info(msg string, fields ...interface{}) {
if l.shouldLog("info") {
l.log.Printf("[INFO] %s %v", msg, fields)
}
}
func (l *Logger) Error(msg string, fields ...interface{}) {
if l.shouldLog("error") {
l.log.Printf("[ERROR] %s %v", msg, fields)
}
}
func (l *Logger) Debug(msg string, fields ...interface{}) {
if l.shouldLog("debug") {
l.log.Printf("[DEBUG] %s %v", msg, fields)
}
}
func (l *Logger) Warn(msg string, fields ...interface{}) {
if l.shouldLog("warn") {
l.log.Printf("[WARN] %s %v", msg, fields)
}
}
func (l *Logger) shouldLog(level string) bool {
levels := map[string]int{
"debug": 0,
"info": 1,
"warn": 2,
"error": 3,
}
currentLevel, ok := levels[l.level]
if !ok {
currentLevel = 1
}
msgLevel, ok := levels[level]
if !ok {
return true
}
return msgLevel >= currentLevel
}