v0.3.7 dependency update refactor
This commit is contained in:
4
go.mod
4
go.mod
@ -3,8 +3,8 @@ module logwisp
|
|||||||
go 1.24.5
|
go 1.24.5
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/lixenwraith/config v0.0.0-20250719015120-e02ee494d440
|
github.com/lixenwraith/config v0.0.0-20250721005322-3b1023974d3d
|
||||||
github.com/lixenwraith/log v0.0.0-20250719031926-25f1c8eb54fa
|
github.com/lixenwraith/log v0.0.0-20250720221103-db34b7e4a2aa
|
||||||
github.com/panjf2000/gnet/v2 v2.9.1
|
github.com/panjf2000/gnet/v2 v2.9.1
|
||||||
github.com/valyala/fasthttp v1.64.0
|
github.com/valyala/fasthttp v1.64.0
|
||||||
)
|
)
|
||||||
|
|||||||
8
go.sum
8
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/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 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
|
||||||
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
|
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-20250721005322-3b1023974d3d h1:h3IWdUA6Fyl5/lvNmPdtKtLFVnZos71aV3RHILYKY/M=
|
||||||
github.com/lixenwraith/config v0.0.0-20250719015120-e02ee494d440/go.mod h1:y7kgDrWIFROWJJ6ASM/SPTRRAj27FjRGWh2SDLcdQ68=
|
github.com/lixenwraith/config v0.0.0-20250721005322-3b1023974d3d/go.mod h1:F8ieHeZgOCPsoym5eynx4kjupfLXBpvJfnX1GzX++EA=
|
||||||
github.com/lixenwraith/log v0.0.0-20250719031926-25f1c8eb54fa h1:Y2AYESKfvDVR1JxRU5aijrGPbbY/cDA28iUDDoSqb2M=
|
github.com/lixenwraith/log v0.0.0-20250720221103-db34b7e4a2aa h1:7x25rdA8azXtY46/MgDQIKTLpZv6TXtqMBCfzL5wSJ4=
|
||||||
github.com/lixenwraith/log v0.0.0-20250719031926-25f1c8eb54fa/go.mod h1:PkY5HFyCZZs2NSeACKbl26ibKqQ6bYyEitMjowgHe/s=
|
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 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||||
github.com/panjf2000/ants/v2 v2.11.3 h1:AfI0ngBoXJmYOpDh9m516vjqoUu2sLrIVgppI9TZVpg=
|
github.com/panjf2000/ants/v2 v2.11.3 h1:AfI0ngBoXJmYOpDh9m516vjqoUu2sLrIVgppI9TZVpg=
|
||||||
|
|||||||
@ -122,8 +122,8 @@ func configureFileLogging(logCfg *log.Config, cfg *config.Config) {
|
|||||||
if cfg.Logging.File != nil {
|
if cfg.Logging.File != nil {
|
||||||
logCfg.Directory = cfg.Logging.File.Directory
|
logCfg.Directory = cfg.Logging.File.Directory
|
||||||
logCfg.Name = cfg.Logging.File.Name
|
logCfg.Name = cfg.Logging.File.Name
|
||||||
logCfg.MaxSizeMB = cfg.Logging.File.MaxSizeMB
|
logCfg.MaxSizeKB = cfg.Logging.File.MaxSizeMB * 1000
|
||||||
logCfg.MaxTotalSizeMB = cfg.Logging.File.MaxTotalSizeMB
|
logCfg.MaxTotalSizeKB = cfg.Logging.File.MaxTotalSizeMB * 1000
|
||||||
if cfg.Logging.File.RetentionHours > 0 {
|
if cfg.Logging.File.RetentionHours > 0 {
|
||||||
logCfg.RetentionPeriodHrs = cfg.Logging.File.RetentionHours
|
logCfg.RetentionPeriodHrs = cfg.Logging.File.RetentionHours
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -74,9 +75,9 @@ func Load(args []string) (*Config, error) {
|
|||||||
cfg, err := lconfig.NewBuilder().
|
cfg, err := lconfig.NewBuilder().
|
||||||
WithDefaults(defaults()).
|
WithDefaults(defaults()).
|
||||||
WithEnvPrefix("LOGWISP_").
|
WithEnvPrefix("LOGWISP_").
|
||||||
WithFile(configPath).
|
|
||||||
WithArgs(args).
|
|
||||||
WithEnvTransform(customEnvTransform).
|
WithEnvTransform(customEnvTransform).
|
||||||
|
WithArgs(args).
|
||||||
|
WithFile(configPath).
|
||||||
WithSources(
|
WithSources(
|
||||||
lconfig.SourceCLI,
|
lconfig.SourceCLI,
|
||||||
lconfig.SourceEnv,
|
lconfig.SourceEnv,
|
||||||
@ -86,23 +87,24 @@ func Load(args []string) (*Config, error) {
|
|||||||
Build()
|
Build()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Config file load errors
|
// Handle file not found errors - maintain existing behavior
|
||||||
if strings.Contains(err.Error(), "not found") {
|
if errors.Is(err, lconfig.ErrConfigNotFound) {
|
||||||
if isExplicit {
|
if isExplicit {
|
||||||
return nil, fmt.Errorf("config file not found: %s", configPath)
|
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 {
|
} else {
|
||||||
return nil, fmt.Errorf("failed to load config: %w", err)
|
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{}
|
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)
|
return nil, fmt.Errorf("failed to scan config: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set config file path if it exists
|
||||||
if _, err := os.Stat(configPath); err == nil {
|
if _, err := os.Stat(configPath); err == nil {
|
||||||
finalConfig.ConfigFile = configPath
|
finalConfig.ConfigFile = configPath
|
||||||
}
|
}
|
||||||
@ -160,7 +162,7 @@ func resolveConfigPath(args []string) (path string, isExplicit bool) {
|
|||||||
func customEnvTransform(path string) string {
|
func customEnvTransform(path string) string {
|
||||||
env := strings.ReplaceAll(path, ".", "_")
|
env := strings.ReplaceAll(path, ".", "_")
|
||||||
env = strings.ToUpper(env)
|
env = strings.ToUpper(env)
|
||||||
env = "LOGWISP_" + env
|
// env = "LOGWISP_" + env // already added by WithEnvPrefix
|
||||||
return env
|
return env
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -40,35 +40,33 @@ func NewFileSink(options map[string]any, logger *log.Logger, formatter format.Fo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create configuration for the internal log writer
|
// Create configuration for the internal log writer
|
||||||
var configArgs []string
|
writerConfig := log.DefaultConfig()
|
||||||
configArgs = append(configArgs,
|
writerConfig.Directory = directory
|
||||||
fmt.Sprintf("directory=%s", directory),
|
writerConfig.Name = name
|
||||||
fmt.Sprintf("name=%s", name),
|
writerConfig.EnableStdout = false // File only
|
||||||
"enable_stdout=false", // File only
|
writerConfig.ShowTimestamp = false // We already have timestamps in entries
|
||||||
"show_timestamp=false", // We already have timestamps in entries
|
writerConfig.ShowLevel = false // We already have levels in entries
|
||||||
"show_level=false", // We already have levels in entries
|
|
||||||
)
|
|
||||||
|
|
||||||
// Add optional configurations
|
// Add optional configurations
|
||||||
if maxSize, ok := options["max_size_mb"].(int64); ok && maxSize > 0 {
|
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 {
|
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 {
|
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 {
|
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
|
// Create internal logger for file writing
|
||||||
writer := log.NewLogger()
|
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)
|
return nil, fmt.Errorf("failed to initialize file writer: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user