diff --git a/rest/adminapitest/admin_api_test.go b/rest/adminapitest/admin_api_test.go index af5d082c2d..2de1102666 100644 --- a/rest/adminapitest/admin_api_test.go +++ b/rest/adminapitest/admin_api_test.go @@ -541,7 +541,7 @@ func TestDBOfflinePutDbConfig(t *testing.T) { // Tests that the users returned in the config endpoint have the correct names // Reproduces #2223 -func TestDBGetConfigNames(t *testing.T) { +func TestDBGetConfigNamesAndDefaultLogging(t *testing.T) { p := "password" rt := rest.NewRestTester(t, @@ -563,11 +563,38 @@ func TestDBGetConfigNames(t *testing.T) { require.NoError(t, base.JSONUnmarshal(response.Body.Bytes(), &body)) assert.Equal(t, len(rt.DatabaseConfig.Users), len(body.Users)) + emptyCnf := &rest.DbLoggingConfig{} + assert.Equal(t, body.Logging, emptyCnf) for k, v := range body.Users { assert.Equal(t, k, *v.Name) } +} + +func TestDBGetConfigCustomLogging(t *testing.T) { + logKeys := []string{base.KeyAccess.String(), base.KeyHTTP.String()} + rt := rest.NewRestTester(t, + &rest.RestTesterConfig{ + DatabaseConfig: &rest.DatabaseConfig{DbConfig: rest.DbConfig{ + Logging: &rest.DbLoggingConfig{ + Console: &rest.DbConsoleLoggingConfig{ + LogLevel: base.LogLevelPtr(base.LevelError), + LogKeys: logKeys, + }, + }, + }, + }, + }, + ) + defer rt.Close() + + response := rt.SendAdminRequest("GET", "/db/_config?include_runtime=true", "") + var body rest.DbConfig + require.NoError(t, base.JSONUnmarshal(response.Body.Bytes(), &body)) + + assert.Equal(t, body.Logging.Console.LogLevel, base.LogLevelPtr(base.LevelError)) + assert.Equal(t, body.Logging.Console.LogKeys, logKeys) } // Take DB offline and ensure can post _resync @@ -3271,6 +3298,8 @@ func TestConfigsIncludeDefaults(t *testing.T) { ctx := base.TestCtx(t) config := rest.BootstrapStartupConfigForTest(t) sc, err := rest.SetupServerContext(ctx, &config, true) + config.Logging.Console.LogKeys = []string{base.KeyDCP.String()} + config.Logging.Console.LogLevel.Set(base.LevelDebug) require.NoError(t, err) defer func() { sc.Close(ctx) @@ -3303,6 +3332,9 @@ func TestConfigsIncludeDefaults(t *testing.T) { assert.Equal(t, false, *dbConfig.StartOffline) assert.Equal(t, db.DefaultCompactInterval, uint32(*dbConfig.CompactIntervalDays)) + assert.Equal(t, dbConfig.Logging.Console.LogLevel.String(), base.LevelDebug.String()) + assert.Equal(t, dbConfig.Logging.Console.LogKeys, []string{base.KeyDCP.String()}) + var runtimeServerConfigResponse rest.RunTimeServerConfigResponse resp = rest.BootstrapAdminRequest(t, http.MethodGet, "/_config?include_runtime=true", "") resp.RequireStatus(http.StatusOK) diff --git a/rest/config_database.go b/rest/config_database.go index 193bd69386..10a50fff3c 100644 --- a/rest/config_database.go +++ b/rest/config_database.go @@ -83,6 +83,20 @@ func GenerateDatabaseConfigVersionID(previousRevID string, dbConfig *DbConfig) ( return hash, nil } +func DefaultPerDBLogging(bootstrapLoggingCnf base.LoggingConfig) *DbLoggingConfig { + if bootstrapLoggingCnf.Console != nil { + if *bootstrapLoggingCnf.Console.Enabled { + return &DbLoggingConfig{ + Console: &DbConsoleLoggingConfig{ + LogLevel: bootstrapLoggingCnf.Console.LogLevel, + LogKeys: bootstrapLoggingCnf.Console.LogKeys, + }, + } + } + } + return &DbLoggingConfig{} +} + // MergeDatabaseConfigWithDefaults merges the passed in config onto a DefaultDbConfig which results in returned value // being populated with defaults when not set func MergeDatabaseConfigWithDefaults(sc *StartupConfig, dbConfig *DbConfig) (*DbConfig, error) { @@ -165,6 +179,7 @@ func DefaultDbConfig(sc *StartupConfig) *DbConfig { ClientPartitionWindowSecs: base.IntPtr(int(base.DefaultClientPartitionWindow.Seconds())), JavascriptTimeoutSecs: base.Uint32Ptr(base.DefaultJavascriptTimeoutSecs), Suspendable: base.BoolPtr(sc.IsServerless()), + Logging: DefaultPerDBLogging(sc.Logging), } revsLimit := db.DefaultRevsLimitNoConflicts