Skip to content

Commit

Permalink
[3.1.2 backport] CBG-3535 remove implicit default of http console log…
Browse files Browse the repository at this point in the history
…ging (#6530)

backport of:

* CBG-3533 remove implicit default of http console logging
* Turn back on HTTP logging for tests

Allows not streaming any logs (including HTTP logs) on capella.
  • Loading branch information
torcolvin committed Oct 13, 2023
1 parent a444554 commit a5f3ebf
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 12 deletions.
3 changes: 0 additions & 3 deletions base/logger_console.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,6 @@ func (lcc *ConsoleLoggerConfig) init() error {
return fmt.Errorf("invalid log level: %v", *lcc.LogLevel)
}

// Always enable the HTTP log key
lcc.LogKeys = append(lcc.LogKeys, logKeyNames[KeyHTTP])

// If ColorEnabled is not explicitly set, use the value of $SG_COLOR
if lcc.ColorEnabled == nil {
// Ignore error parsing this value to treat it as false.
Expand Down
24 changes: 20 additions & 4 deletions base/logger_console_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ func TestConsoleLogDefaults(t *testing.T) {
expected: ConsoleLogger{
FileLogger: FileLogger{Enabled: AtomicBool{0}},
LogLevel: logLevelPtr(LevelNone),
LogKeyMask: logKeyMask(KeyHTTP),
LogKeyMask: logKeyMask(KeyNone),
config: ConsoleLoggerConfig{LogKeys: []string{}},
isStderr: false,
},
},
Expand All @@ -232,7 +233,8 @@ func TestConsoleLogDefaults(t *testing.T) {
expected: ConsoleLogger{
FileLogger: FileLogger{Enabled: AtomicBool{1}},
LogLevel: logLevelPtr(LevelInfo),
LogKeyMask: logKeyMask(KeyHTTP, KeyCRUD),
LogKeyMask: logKeyMask(KeyCRUD),
config: ConsoleLoggerConfig{LogKeys: []string{"CRUD"}},
isStderr: true,
},
},
Expand All @@ -242,7 +244,8 @@ func TestConsoleLogDefaults(t *testing.T) {
expected: ConsoleLogger{
FileLogger: FileLogger{Enabled: AtomicBool{1}},
LogLevel: logLevelPtr(LevelWarn),
LogKeyMask: logKeyMask(KeyHTTP),
LogKeyMask: logKeyMask(KeyNone),
config: ConsoleLoggerConfig{LogKeys: nil},
isStderr: true,
},
},
Expand All @@ -252,7 +255,19 @@ func TestConsoleLogDefaults(t *testing.T) {
expected: ConsoleLogger{
FileLogger: FileLogger{Enabled: AtomicBool{1}},
LogLevel: logLevelPtr(LevelWarn),
LogKeyMask: logKeyMask(KeyHTTP, KeyCRUD),
LogKeyMask: logKeyMask(KeyCRUD),
config: ConsoleLoggerConfig{LogKeys: []string{"CRUD"}},
isStderr: true,
},
},
{
name: "http default",
config: ConsoleLoggerConfig{LogKeys: []string{"HTTP"}},
expected: ConsoleLogger{
FileLogger: FileLogger{Enabled: AtomicBool{1}},
LogLevel: logLevelPtr(LevelInfo),
LogKeyMask: logKeyMask(KeyHTTP),
config: ConsoleLoggerConfig{LogKeys: []string{"HTTP"}},
isStderr: true,
},
},
Expand All @@ -267,6 +282,7 @@ func TestConsoleLogDefaults(t *testing.T) {
assert.Equal(tt, *test.expected.LogLevel, *logger.LogLevel)
assert.Equal(tt, *test.expected.LogKeyMask, *logger.LogKeyMask)
assert.Equal(tt, test.expected.isStderr, logger.isStderr)
assert.Equal(tt, test.expected.config.LogKeys, logger.config.LogKeys)
})
}
}
2 changes: 1 addition & 1 deletion base/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func init() {
// initializing a logging config, and when running under a test scenario.
initialCollationBufferSize := 0

consoleLogger = mustInitConsoleLogger(context.Background(), &ConsoleLoggerConfig{FileLoggerConfig: FileLoggerConfig{Enabled: BoolPtr(true), CollationBufferSize: &initialCollationBufferSize}})
consoleLogger = mustInitConsoleLogger(context.Background(), &ConsoleLoggerConfig{LogKeys: []string{logKeyNames[KeyHTTP]}, FileLoggerConfig: FileLoggerConfig{Enabled: BoolPtr(true), CollationBufferSize: &initialCollationBufferSize}})
initExternalLoggers()
}

Expand Down
4 changes: 2 additions & 2 deletions base/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -644,15 +644,15 @@ func TestSetTestLogging(t *testing.T) {

cleanup()
assert.Equal(t, LevelInfo, *consoleLogger.LogLevel)
assert.Equal(t, *logKeyMask(KeyHTTP), *consoleLogger.LogKeyMask)
require.Equal(t, *logKeyMask(KeyHTTP), *consoleLogger.LogKeyMask)

cleanup = setTestLogging(LevelNone, "", KeyNone)
assert.Equal(t, LevelNone, *consoleLogger.LogLevel)
assert.Equal(t, *logKeyMask(KeyNone), *consoleLogger.LogKeyMask)

cleanup()
assert.Equal(t, LevelInfo, *consoleLogger.LogLevel)
assert.Equal(t, *logKeyMask(KeyHTTP), *consoleLogger.LogKeyMask)
require.Equal(t, *logKeyMask(KeyHTTP), *consoleLogger.LogKeyMask)

cleanup = setTestLogging(LevelDebug, "", KeyDCP, KeySync)
assert.Equal(t, LevelDebug, *consoleLogger.LogLevel)
Expand Down
4 changes: 2 additions & 2 deletions rest/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1412,13 +1412,13 @@ func TestDefaultLogging(t *testing.T) {

require.NoError(t, config.SetupAndValidateLogging(base.TestCtx(t)))
assert.Equal(t, base.LevelNone, *base.ConsoleLogLevel())
assert.Equal(t, []string{"HTTP"}, base.ConsoleLogKey().EnabledLogKeys())
assert.Equal(t, []string{}, base.ConsoleLogKey().EnabledLogKeys())

// setting just a log key should enable logging
config.Logging.Console = &base.ConsoleLoggerConfig{LogKeys: []string{"CRUD"}}
require.NoError(t, config.SetupAndValidateLogging(base.TestCtx(t)))
assert.Equal(t, base.LevelInfo, *base.ConsoleLogLevel())
assert.Equal(t, []string{"CRUD", "HTTP"}, base.ConsoleLogKey().EnabledLogKeys())
assert.Equal(t, []string{"CRUD"}, base.ConsoleLogKey().EnabledLogKeys())
}

func TestSetupServerContext(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions rest/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func TestParseHTTPRangeHeader(t *testing.T) {

func TestHTTPLoggingRedaction(t *testing.T) {

base.SetUpTestLogging(t, base.LevelInfo, base.KeyHTTP)
base.LongRunningTest(t)
rt := NewRestTester(t, nil)
defer rt.Close()
Expand Down

0 comments on commit a5f3ebf

Please sign in to comment.