1
0
mirror of https://github.com/pocket-id/pocket-id.git synced 2026-02-09 19:39:17 +00:00

feat: add support for LOG_LEVEL env variable (#942)

This commit is contained in:
Elias Schneider
2025-09-14 17:26:21 +02:00
committed by GitHub
parent a897b31166
commit 2d6d5df0e7
6 changed files with 54 additions and 48 deletions

View File

@@ -10,6 +10,7 @@ import (
"strings"
"github.com/caarlos0/env/v11"
sloggin "github.com/gin-contrib/slog"
_ "github.com/joho/godotenv/autoload"
)
@@ -32,6 +33,7 @@ const (
type EnvConfigSchema struct {
AppEnv string `env:"APP_ENV"`
LogLevel string `env:"LOG_LEVEL"`
AppURL string `env:"APP_URL"`
DbProvider DbProvider `env:"DB_PROVIDER"`
DbConnectionString string `env:"DB_CONNECTION_STRING" options:"file"`
@@ -70,6 +72,7 @@ func init() {
func defaultConfig() EnvConfigSchema {
return EnvConfigSchema{
AppEnv: "production",
LogLevel: "info",
DbProvider: "sqlite",
DbConnectionString: "",
UploadPath: "data/uploads",
@@ -115,6 +118,11 @@ func parseEnvConfig() error {
}
// Validate the environment variables
EnvConfig.LogLevel = strings.ToLower(EnvConfig.LogLevel)
if _, err := sloggin.ParseLevel(EnvConfig.LogLevel); err != nil {
return errors.New("invalid LOG_LEVEL value. Must be 'debug', 'info', 'warn' or 'error'")
}
switch EnvConfig.DbProvider {
case DbProviderSqlite:
if EnvConfig.DbConnectionString == "" {