From 6886488abdc7834aecc3f526c973c12f0f01265d Mon Sep 17 00:00:00 2001 From: jafar75 Date: Tue, 26 Dec 2023 03:21:27 +0330 Subject: [PATCH 1/3] add group name to log --- cmd/run.go | 1 + logging/logger.go | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/cmd/run.go b/cmd/run.go index 3101c645..5af40ec5 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -237,6 +237,7 @@ var runCmd = &cobra.Command{ SyslogPriority: cfg.GetSyslogPriority(), RSyslogNetwork: cfg.RSyslogNetwork, RSyslogAddress: cfg.RSyslogAddress, + Name: name, }) } diff --git a/logging/logger.go b/logging/logger.go index c52087f7..c7fbcc4f 100644 --- a/logging/logger.go +++ b/logging/logger.go @@ -35,6 +35,9 @@ type LoggerConfig struct { MaxAge int Compress bool LocalTime bool + + // group name + Name string } // NewLogger creates a new logger with the given configuration. @@ -96,6 +99,7 @@ func NewLogger(ctx context.Context, cfg LoggerConfig) zerolog.Logger { multiWriter := zerolog.MultiLevelWriter(outputs...) logger := zerolog.New(multiWriter) logger = logger.With().Timestamp().Logger() + logger = logger.With().Any("group", cfg.Name).Logger() span.End() From 21d444b0b27226d2b3356579bfa9dd9cff5a6ac9 Mon Sep 17 00:00:00 2001 From: jafar75 Date: Tue, 26 Dec 2023 03:35:03 +0330 Subject: [PATCH 2/3] edit tests --- cmd/run_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd/run_test.go b/cmd/run_test.go index f104e1e7..1925d6b1 100644 --- a/cmd/run_test.go +++ b/cmd/run_test.go @@ -38,7 +38,7 @@ func Test_runCmd(t *testing.T) { runCmd.Print(output) // Check if GatewayD started and stopped correctly. assert.Contains(t, output, "GatewayD is running") - assert.Contains(t, output, "Stopped all servers\n") + assert.Contains(t, output, "Stopped all servers") waitGroup.Done() }(&waitGroup) @@ -94,7 +94,7 @@ func Test_runCmdWithTLS(t *testing.T) { // Check if GatewayD started and stopped correctly. assert.Contains(t, output, "GatewayD is running") assert.Contains(t, output, "TLS is enabled") - assert.Contains(t, output, "Stopped all servers\n") + assert.Contains(t, output, "Stopped all servers") waitGroup.Done() }(&waitGroup) @@ -147,11 +147,11 @@ func Test_runCmdWithMultiTenancy(t *testing.T) { runCmd.Print(output) // Check if GatewayD started and stopped correctly. assert.Contains(t, output, "GatewayD is running") - assert.Contains(t, output, "There are clients available in the pool count=10 name=default") - assert.Contains(t, output, "There are clients available in the pool count=10 name=test") + assert.Contains(t, output, "There are clients available in the pool count=10 group=default name=default") + assert.Contains(t, output, "There are clients available in the pool count=10 group=test name=test") assert.Contains(t, output, "GatewayD is listening address=0.0.0.0:15432") assert.Contains(t, output, "GatewayD is listening address=0.0.0.0:15433") - assert.Contains(t, output, "Stopped all servers\n") + assert.Contains(t, output, "Stopped all servers") waitGroup.Done() }(&waitGroup) @@ -227,7 +227,7 @@ func Test_runCmdWithCachePlugin(t *testing.T) { runCmd.Print(output) // Check if GatewayD started and stopped correctly. assert.Contains(t, output, "GatewayD is running") - assert.Contains(t, output, "Stopped all servers\n") + assert.Contains(t, output, "Stopped all servers") waitGroup.Done() }(&waitGroup) From d3e0f55d7cfa8f18f8d9abf54ba59a564637a84f Mon Sep 17 00:00:00 2001 From: jafar75 Date: Tue, 26 Dec 2023 16:08:42 +0330 Subject: [PATCH 3/3] apply comments --- cmd/run_test.go | 4 ++-- logging/logger.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/run_test.go b/cmd/run_test.go index 1925d6b1..ebaae822 100644 --- a/cmd/run_test.go +++ b/cmd/run_test.go @@ -147,8 +147,8 @@ func Test_runCmdWithMultiTenancy(t *testing.T) { runCmd.Print(output) // Check if GatewayD started and stopped correctly. assert.Contains(t, output, "GatewayD is running") - assert.Contains(t, output, "There are clients available in the pool count=10 group=default name=default") - assert.Contains(t, output, "There are clients available in the pool count=10 group=test name=test") + assert.Contains(t, output, "There are clients available in the pool count=10 group=default") + assert.Contains(t, output, "There are clients available in the pool count=10 group=test") assert.Contains(t, output, "GatewayD is listening address=0.0.0.0:15432") assert.Contains(t, output, "GatewayD is listening address=0.0.0.0:15433") assert.Contains(t, output, "Stopped all servers") diff --git a/logging/logger.go b/logging/logger.go index c7fbcc4f..1048ff4d 100644 --- a/logging/logger.go +++ b/logging/logger.go @@ -99,7 +99,7 @@ func NewLogger(ctx context.Context, cfg LoggerConfig) zerolog.Logger { multiWriter := zerolog.MultiLevelWriter(outputs...) logger := zerolog.New(multiWriter) logger = logger.With().Timestamp().Logger() - logger = logger.With().Any("group", cfg.Name).Logger() + logger = logger.With().Str("group", cfg.Name).Logger() span.End()