From 5aa732b0969102f7a67e21e92accaf104a86f98db6fa758eb4bfc0e833eabd12 Mon Sep 17 00:00:00 2001 From: Lixen Wraith Date: Mon, 21 Jul 2025 02:40:37 -0400 Subject: [PATCH] v0.3.7 dependency update refactor --- go.mod | 4 ++-- go.sum | 8 ++++---- src/cmd/logwisp/bootstrap.go | 4 ++-- src/internal/config/loader.go | 18 ++++++++++-------- src/internal/sink/file.go | 24 +++++++++++------------- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/go.mod b/go.mod index 413bb3b..613b8bc 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,8 @@ module logwisp go 1.24.5 require ( - github.com/lixenwraith/config v0.0.0-20250719015120-e02ee494d440 - github.com/lixenwraith/log v0.0.0-20250719031926-25f1c8eb54fa + github.com/lixenwraith/config v0.0.0-20250721005322-3b1023974d3d + github.com/lixenwraith/log v0.0.0-20250720221103-db34b7e4a2aa github.com/panjf2000/gnet/v2 v2.9.1 github.com/valyala/fasthttp v1.64.0 ) diff --git a/go.sum b/go.sum index add85a8..17e68f1 100644 --- a/go.sum +++ b/go.sum @@ -6,10 +6,10 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo= github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ= -github.com/lixenwraith/config v0.0.0-20250719015120-e02ee494d440 h1:O6nHnpeDfIYQ1WxCtA2gkm8upQ4RW21DUMlQz5DKJCU= -github.com/lixenwraith/config v0.0.0-20250719015120-e02ee494d440/go.mod h1:y7kgDrWIFROWJJ6ASM/SPTRRAj27FjRGWh2SDLcdQ68= -github.com/lixenwraith/log v0.0.0-20250719031926-25f1c8eb54fa h1:Y2AYESKfvDVR1JxRU5aijrGPbbY/cDA28iUDDoSqb2M= -github.com/lixenwraith/log v0.0.0-20250719031926-25f1c8eb54fa/go.mod h1:PkY5HFyCZZs2NSeACKbl26ibKqQ6bYyEitMjowgHe/s= +github.com/lixenwraith/config v0.0.0-20250721005322-3b1023974d3d h1:h3IWdUA6Fyl5/lvNmPdtKtLFVnZos71aV3RHILYKY/M= +github.com/lixenwraith/config v0.0.0-20250721005322-3b1023974d3d/go.mod h1:F8ieHeZgOCPsoym5eynx4kjupfLXBpvJfnX1GzX++EA= +github.com/lixenwraith/log v0.0.0-20250720221103-db34b7e4a2aa h1:7x25rdA8azXtY46/MgDQIKTLpZv6TXtqMBCfzL5wSJ4= +github.com/lixenwraith/log v0.0.0-20250720221103-db34b7e4a2aa/go.mod h1:asd0/TQplmacopOKWcqW0jysau/lWohR2Fe29KBSp2w= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/panjf2000/ants/v2 v2.11.3 h1:AfI0ngBoXJmYOpDh9m516vjqoUu2sLrIVgppI9TZVpg= diff --git a/src/cmd/logwisp/bootstrap.go b/src/cmd/logwisp/bootstrap.go index 9a89e0c..b20c48b 100644 --- a/src/cmd/logwisp/bootstrap.go +++ b/src/cmd/logwisp/bootstrap.go @@ -122,8 +122,8 @@ func configureFileLogging(logCfg *log.Config, cfg *config.Config) { if cfg.Logging.File != nil { logCfg.Directory = cfg.Logging.File.Directory logCfg.Name = cfg.Logging.File.Name - logCfg.MaxSizeMB = cfg.Logging.File.MaxSizeMB - logCfg.MaxTotalSizeMB = cfg.Logging.File.MaxTotalSizeMB + logCfg.MaxSizeKB = cfg.Logging.File.MaxSizeMB * 1000 + logCfg.MaxTotalSizeKB = cfg.Logging.File.MaxTotalSizeMB * 1000 if cfg.Logging.File.RetentionHours > 0 { logCfg.RetentionPeriodHrs = cfg.Logging.File.RetentionHours } diff --git a/src/internal/config/loader.go b/src/internal/config/loader.go index 23b6e08..568300e 100644 --- a/src/internal/config/loader.go +++ b/src/internal/config/loader.go @@ -2,6 +2,7 @@ package config import ( + "errors" "fmt" "os" "path/filepath" @@ -74,9 +75,9 @@ func Load(args []string) (*Config, error) { cfg, err := lconfig.NewBuilder(). WithDefaults(defaults()). WithEnvPrefix("LOGWISP_"). - WithFile(configPath). - WithArgs(args). WithEnvTransform(customEnvTransform). + WithArgs(args). + WithFile(configPath). WithSources( lconfig.SourceCLI, lconfig.SourceEnv, @@ -86,23 +87,24 @@ func Load(args []string) (*Config, error) { Build() if err != nil { - // Config file load errors - if strings.Contains(err.Error(), "not found") { + // Handle file not found errors - maintain existing behavior + if errors.Is(err, lconfig.ErrConfigNotFound) { if isExplicit { return nil, fmt.Errorf("config file not found: %s", configPath) } - // If the default config file is not found, it's not an error. + // If the default config file is not found, it's not an error } else { return nil, fmt.Errorf("failed to load config: %w", err) } } - // Scan into final config struct + // Scan into final config struct - using new interface finalConfig := &Config{} - if err := cfg.Scan("", finalConfig); err != nil { + if err := cfg.Scan(finalConfig); err != nil { return nil, fmt.Errorf("failed to scan config: %w", err) } + // Set config file path if it exists if _, err := os.Stat(configPath); err == nil { finalConfig.ConfigFile = configPath } @@ -160,7 +162,7 @@ func resolveConfigPath(args []string) (path string, isExplicit bool) { func customEnvTransform(path string) string { env := strings.ReplaceAll(path, ".", "_") env = strings.ToUpper(env) - env = "LOGWISP_" + env + // env = "LOGWISP_" + env // already added by WithEnvPrefix return env } diff --git a/src/internal/sink/file.go b/src/internal/sink/file.go index 8b6a11f..e0c12ac 100644 --- a/src/internal/sink/file.go +++ b/src/internal/sink/file.go @@ -40,35 +40,33 @@ func NewFileSink(options map[string]any, logger *log.Logger, formatter format.Fo } // Create configuration for the internal log writer - var configArgs []string - configArgs = append(configArgs, - fmt.Sprintf("directory=%s", directory), - fmt.Sprintf("name=%s", name), - "enable_stdout=false", // File only - "show_timestamp=false", // We already have timestamps in entries - "show_level=false", // We already have levels in entries - ) + writerConfig := log.DefaultConfig() + writerConfig.Directory = directory + writerConfig.Name = name + writerConfig.EnableStdout = false // File only + writerConfig.ShowTimestamp = false // We already have timestamps in entries + writerConfig.ShowLevel = false // We already have levels in entries // Add optional configurations if maxSize, ok := options["max_size_mb"].(int64); ok && maxSize > 0 { - configArgs = append(configArgs, fmt.Sprintf("max_size_mb=%d", maxSize)) + writerConfig.MaxSizeKB = maxSize * 1000 } if maxTotalSize, ok := options["max_total_size_mb"].(int64); ok && maxTotalSize >= 0 { - configArgs = append(configArgs, fmt.Sprintf("max_total_size_mb=%d", maxTotalSize)) + writerConfig.MaxTotalSizeKB = maxTotalSize * 1000 } if retention, ok := options["retention_hours"].(int64); ok && retention > 0 { - configArgs = append(configArgs, fmt.Sprintf("retention_period_hrs=%.1f", retention)) + writerConfig.RetentionPeriodHrs = float64(retention) } if minDiskFree, ok := options["min_disk_free_mb"].(int64); ok && minDiskFree > 0 { - configArgs = append(configArgs, fmt.Sprintf("min_disk_free_mb=%d", minDiskFree)) + writerConfig.MinDiskFreeKB = minDiskFree * 1000 } // Create internal logger for file writing writer := log.NewLogger() - if err := writer.ApplyOverride(configArgs...); err != nil { + if err := writer.ApplyConfig(writerConfig); err != nil { return nil, fmt.Errorf("failed to initialize file writer: %w", err) }