AGENTS.md: no direct commits to main, all changes via feature branches
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
// Package logger provides structured logging for the application.
|
||||
package logger
|
||||
|
||||
import (
|
||||
@@ -8,18 +9,22 @@ import (
|
||||
"go.uber.org/fx"
|
||||
)
|
||||
|
||||
// LoggerParams defines the dependencies for creating a Logger.
|
||||
type LoggerParams struct {
|
||||
fx.In
|
||||
|
||||
Globals *globals.Globals
|
||||
}
|
||||
|
||||
// Logger wraps slog with application-specific configuration.
|
||||
type Logger struct {
|
||||
log *slog.Logger
|
||||
level *slog.LevelVar
|
||||
params LoggerParams
|
||||
}
|
||||
|
||||
func New(lc fx.Lifecycle, params LoggerParams) (*Logger, error) {
|
||||
// New creates a new Logger with appropriate handler based on terminal detection.
|
||||
func New(_ fx.Lifecycle, params LoggerParams) (*Logger, error) {
|
||||
l := new(Logger)
|
||||
l.level = new(slog.LevelVar)
|
||||
l.level.Set(slog.LevelInfo)
|
||||
@@ -48,15 +53,18 @@ func New(lc fx.Lifecycle, params LoggerParams) (*Logger, error) {
|
||||
return l, nil
|
||||
}
|
||||
|
||||
// EnableDebugLogging switches the log level to debug.
|
||||
func (l *Logger) EnableDebugLogging() {
|
||||
l.level.Set(slog.LevelDebug)
|
||||
l.log.Debug("debug logging enabled", "debug", true)
|
||||
}
|
||||
|
||||
// Get returns the underlying slog.Logger.
|
||||
func (l *Logger) Get() *slog.Logger {
|
||||
return l.log
|
||||
}
|
||||
|
||||
// Identify logs the application name and version at startup.
|
||||
func (l *Logger) Identify() {
|
||||
l.log.Info("starting",
|
||||
"appname", l.params.Globals.Appname,
|
||||
|
||||
Reference in New Issue
Block a user