Skip to content

Commit

Permalink
Merge pull request #394 from gatewayd-io/add-group-name-to-log-lines
Browse files Browse the repository at this point in the history
Add group name to log
  • Loading branch information
mostafa authored Dec 26, 2023
2 parents 890d562 + d3e0f55 commit 155edc2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ var runCmd = &cobra.Command{
SyslogPriority: cfg.GetSyslogPriority(),
RSyslogNetwork: cfg.RSyslogNetwork,
RSyslogAddress: cfg.RSyslogAddress,
Name: name,
})
}

Expand Down
12 changes: 6 additions & 6 deletions cmd/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
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\n")
assert.Contains(t, output, "Stopped all servers")

waitGroup.Done()
}(&waitGroup)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions logging/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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().Str("group", cfg.Name).Logger()

span.End()

Expand Down

0 comments on commit 155edc2

Please sign in to comment.