Refactor error handling and utility functions; remove deprecated code and improve logging

This commit is contained in:
alex
2025-07-05 16:05:03 +03:00
parent b70819e976
commit 2fdc32ce9f
13 changed files with 132 additions and 162 deletions

View File

@@ -1,3 +1,6 @@
// Package logs provides a logger setup function that configures the logger based on the environment.
// It supports different logging levels for development and production environments.
// It uses the standard library's slog package for structured logging.
package logs
import (
@@ -5,11 +8,15 @@ import (
"os"
)
// Environment constants for logger setup
const (
envDev = "dev"
// envDev enables development logging with debug level
envDev = "dev"
// envProd enables production logging with info level
envProd = "prod"
)
// SetupLogger initializes and returns a logger based on the provided environment.
func SetupLogger(env string) *slog.Logger {
var log *slog.Logger
switch env {

View File

@@ -6,30 +6,20 @@ import (
"sync"
)
// MockHandler is a mock implementation of slog.Handler for testing purposes.
type MockHandler struct {
mu sync.Mutex
mu sync.Mutex
// Logs stores the log records captured by the handler.
Logs []slog.Record
}
func NewMockHandler() *MockHandler {
return &MockHandler{}
}
func (h *MockHandler) Enabled(_ context.Context, _ slog.Level) bool {
return true
}
func NewMockHandler() *MockHandler { return &MockHandler{} }
func (h *MockHandler) Enabled(_ context.Context, _ slog.Level) bool { return true }
func (h *MockHandler) WithAttrs(_ []slog.Attr) slog.Handler { return h }
func (h *MockHandler) WithGroup(_ string) slog.Handler { return h }
func (h *MockHandler) Handle(_ context.Context, r slog.Record) error {
h.mu.Lock()
defer h.mu.Unlock()
h.Logs = append(h.Logs, r.Clone())
return nil
}
func (h *MockHandler) WithAttrs(_ []slog.Attr) slog.Handler {
return h
}
func (h *MockHandler) WithGroup(_ string) slog.Handler {
return h
}