mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-05 23:44:22 +00:00
Initial logging implementation
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user