Initial logging implementation

This commit is contained in:
2024-12-10 22:16:50 +01:00
parent 3d03da221b
commit ea916c3ecc
3 changed files with 304 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ package app
import (
"fmt"
"novamd/internal/logging"
"novamd/internal/secrets"
"os"
"strconv"
@@ -25,6 +26,9 @@ type Config struct {
RateLimitRequests int
RateLimitWindow time.Duration
IsDevelopment bool
LogDir string
LogLevel logging.LogLevel
ConsoleOutput bool
}
// DefaultConfig returns a new Config instance with default values
@@ -37,6 +41,9 @@ func DefaultConfig() *Config {
RateLimitRequests: 100,
RateLimitWindow: time.Minute * 15,
IsDevelopment: false,
LogDir: "./logs",
LogLevel: logging.INFO,
ConsoleOutput: true,
}
}
@@ -108,6 +115,29 @@ func LoadConfig() (*Config, error) {
}
}
// Configure log directory
if logDir := os.Getenv("NOVAMD_LOG_DIR"); logDir != "" {
config.LogDir = logDir
}
// Configure log level, if isDevelopment is set, default to debug
if logLevel := os.Getenv("NOVAMD_LOG_LEVEL"); logLevel != "" {
if parsed, err := logging.ParseLogLevel(logLevel); err == nil {
config.LogLevel = parsed
}
} else if config.IsDevelopment {
config.LogLevel = logging.DEBUG
}
// Configure console output, if isDevelopment is set, default to true
if consoleOutput := os.Getenv("NOVAMD_CONSOLE_OUTPUT"); consoleOutput != "" {
if parsed, err := strconv.ParseBool(consoleOutput); err == nil {
config.ConsoleOutput = parsed
}
} else if config.IsDevelopment {
config.ConsoleOutput = true
}
// Validate all settings
if err := config.validate(); err != nil {
return nil, err