From 10781dd319d74640a0eaeaa7ce4f0042af3b3fa4 Mon Sep 17 00:00:00 2001 From: reshke kirill Date: Tue, 2 Jun 2026 20:53:00 +0000 Subject: [PATCH 1/3] Support log level severity change with SIGUSR1 --- cmd/client/main.go | 5 +---- cmd/yproxy/main.go | 10 +++------- config/instance.go | 13 +++++++++++++ pkg/core/core.go | 11 ++++++++++- pkg/ylogger/logger.go | 13 ++----------- 5 files changed, 29 insertions(+), 23 deletions(-) diff --git a/cmd/client/main.go b/cmd/client/main.go index 1eb1cf2..3231280 100644 --- a/cmd/client/main.go +++ b/cmd/client/main.go @@ -3,7 +3,6 @@ package main import ( "fmt" "io" - "log" "net" "os" @@ -63,9 +62,7 @@ func Runner(f func(net.Conn, *config.Instance, []string) error) func(*cobra.Comm logLevel = instanceCnf.LogLevel } - if err := ylogger.UpdateZeroLogLevel(logLevel); err != nil { - log.Printf("failed to update log level: %s\n", err) - } + ylogger.ReloadLogger(instanceCnf.LogPath, logLevel) defer func() { _ = con.Close() diff --git a/cmd/yproxy/main.go b/cmd/yproxy/main.go index 37fbd30..ea64dbd 100644 --- a/cmd/yproxy/main.go +++ b/cmd/yproxy/main.go @@ -1,8 +1,6 @@ package main import ( - "log" - "github.com/spf13/cobra" "github.com/yezzey-gp/yproxy/config" @@ -30,14 +28,12 @@ var rootCmd = &cobra.Command{ instance := core.NewInstance() - if instanceCnf.LogPath != "" { - ylogger.ReloadLogger(instanceCnf.LogPath) - } if logLevel == "" { logLevel = instanceCnf.LogLevel } - if err := ylogger.UpdateZeroLogLevel(logLevel); err != nil { - log.Printf("failed to update log level: %s\n", err) + + if instanceCnf.LogPath != "" { + ylogger.ReloadLogger(instanceCnf.LogPath, logLevel) } return instance.Run(instanceCnf) diff --git a/config/instance.go b/config/instance.go index 702ac69..5011ae0 100644 --- a/config/instance.go +++ b/config/instance.go @@ -121,7 +121,20 @@ func EmbedDefaults(cfgInstance *Instance) { cfgInstance.YezzeyRestoreParanoid = false } +var ( + bootstrapCfgPath = "" +) + +func ReloadInstanceConfig() (*Instance, error) { + LoadInstanceConfig(bootstrapCfgPath) + return InstanceConfig(), nil +} + func LoadInstanceConfig(cfgPath string) (err error) { + if bootstrapCfgPath != "" && bootstrapCfgPath != cfgPath { + return fmt.Errorf("bootrap config path already set") + } + bootstrapCfgPath = cfgPath cfgInstance, err = ReadInstanceConfig(cfgPath) if err != nil { return diff --git a/pkg/core/core.go b/pkg/core/core.go index a4a7a38..d8afb01 100644 --- a/pkg/core/core.go +++ b/pkg/core/core.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "log" "net" "os" "os/signal" @@ -80,7 +81,15 @@ func (i *Instance) Run(instanceCnf *config.Instance) error { switch s { case syscall.SIGUSR1: - ylogger.ReloadLogger(instanceCnf.LogPath) + instanceCnf, err := config.ReloadInstanceConfig() + + if err != nil { + log.Printf("failed to update log level: %s\n", err) + continue + } + + ylogger.ReloadLogger(instanceCnf.LogPath, instanceCnf.LogLevel) + case syscall.SIGHUP: if dws != nil { err := dws.ServeFor(time.Duration(instanceCnf.DebugMinutes) * time.Minute) diff --git a/pkg/ylogger/logger.go b/pkg/ylogger/logger.go index 38a1be3..00eae33 100644 --- a/pkg/ylogger/logger.go +++ b/pkg/ylogger/logger.go @@ -33,18 +33,9 @@ func NewZeroLogger(filepath string) *zerolog.Logger { return &logger } -func UpdateZeroLogLevel(logLevel string) error { +func ReloadLogger(filepath string, logLevel string) { level := parseLevel(logLevel) - zeroLogger := Zero.With().Logger().Level(level) - Zero = &zeroLogger - return nil -} - -func ReloadLogger(filepath string) { - if filepath == "" { // - return // this means os.Stdout, so no need to open new file - } - newLogger := NewZeroLogger(filepath).Level(Zero.GetLevel()) + newLogger := NewZeroLogger(filepath).Level(level) Zero = &newLogger } From 897e4f8fd92fdb250bdb4e8d6d50b1c2b58e1890 Mon Sep 17 00:00:00 2001 From: reshke kirill Date: Wed, 3 Jun 2026 04:21:06 +0000 Subject: [PATCH 2/3] check --- config/instance.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/config/instance.go b/config/instance.go index 5011ae0..6a8871b 100644 --- a/config/instance.go +++ b/config/instance.go @@ -126,7 +126,9 @@ var ( ) func ReloadInstanceConfig() (*Instance, error) { - LoadInstanceConfig(bootstrapCfgPath) + if err := LoadInstanceConfig(bootstrapCfgPath); err != nil { + return nil, err + } return InstanceConfig(), nil } From 6803c5fd2cb8a586c9d132a69235587751f88f92 Mon Sep 17 00:00:00 2001 From: reshke kirill Date: Wed, 3 Jun 2026 04:23:21 +0000 Subject: [PATCH 3/3] spell --- config/instance.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/instance.go b/config/instance.go index 6a8871b..146d343 100644 --- a/config/instance.go +++ b/config/instance.go @@ -134,7 +134,7 @@ func ReloadInstanceConfig() (*Instance, error) { func LoadInstanceConfig(cfgPath string) (err error) { if bootstrapCfgPath != "" && bootstrapCfgPath != cfgPath { - return fmt.Errorf("bootrap config path already set") + return fmt.Errorf("bootstrap config path already set") } bootstrapCfgPath = cfgPath cfgInstance, err = ReadInstanceConfig(cfgPath)