feat: tipos Logger, LogLevel y LogEntry para structured logging (infra)
Tipos base para las funciones de structured logging sobre log/slog: - LogLevel: suma enum Debug/Info/Warn/Error - Logger: wrapper producto con nivel, output, formato y fields contextuales - LogEntry: modelo canonico JSON para tests y pipelines de logs Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
package infra
|
||||
|
||||
import "time"
|
||||
|
||||
// LogEntry representa una entrada de log estructurada serializable a JSON.
|
||||
// Se usa como modelo canonico para tests y para pipelines que procesan logs.
|
||||
type LogEntry struct {
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
Level string `json:"level"`
|
||||
Message string `json:"message"`
|
||||
Fields map[string]any `json:"fields,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package infra
|
||||
|
||||
// LogLevel representa los niveles de log soportados por el Logger.
|
||||
// El orden implicito es Debug < Info < Warn < Error.
|
||||
type LogLevel int
|
||||
|
||||
const (
|
||||
// LogLevelDebug es el nivel mas verbose, util para trazas de desarrollo.
|
||||
LogLevelDebug LogLevel = iota
|
||||
// LogLevelInfo es el nivel por defecto para eventos normales del sistema.
|
||||
LogLevelInfo
|
||||
// LogLevelWarn indica situaciones anomalas que no impiden el funcionamiento.
|
||||
LogLevelWarn
|
||||
// LogLevelError indica fallos que requieren atencion.
|
||||
LogLevelError
|
||||
)
|
||||
@@ -0,0 +1,16 @@
|
||||
package infra
|
||||
|
||||
import (
|
||||
"io"
|
||||
"log/slog"
|
||||
)
|
||||
|
||||
// Logger wrappea slog.Logger con config del registry (nivel, output, formato, campos contextuales).
|
||||
// Se crea con LoggerNew y se clona inmutablemente con LoggerWith anadiendo campos.
|
||||
type Logger struct {
|
||||
Level LogLevel // nivel minimo filtrado
|
||||
Output io.Writer // destino de los logs (stdout, stderr, file, buffer)
|
||||
Format string // "json" | "text"
|
||||
Fields map[string]any // campos contextuales adjuntos al logger
|
||||
inner *slog.Logger // handler real de slog
|
||||
}
|
||||
Reference in New Issue
Block a user