Skip to content

Commit

Permalink
Change variable to include all globals
Browse files Browse the repository at this point in the history
  • Loading branch information
torcolvin committed Jan 10, 2024
1 parent 83f1e87 commit 0b0675e
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions rest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ var (
// The value of defaultLogFilePath is populated by -defaultLogFilePath by command line flag from service scripts.
defaultLogFilePath string

// serverContextLoggingInitialized is set the first time that logging has been initialized
serverContextLoggingInitialized = atomic.Bool{}
// serverContextGlobalsInitialized is set the first time that a server context has been initialized
serverContextGlobalsInitialized = atomic.Bool{}
)

const (
Expand Down Expand Up @@ -1349,9 +1349,9 @@ func (sc *StartupConfig) Validate(ctx context.Context, isEnterpriseEdition bool)
// SetupServerContext creates a new ServerContext given its configuration and performs the context validation.
func SetupServerContext(ctx context.Context, config *StartupConfig, persistentConfig bool) (*ServerContext, error) {
// If SetupServerContext is called while any other go routines that might use logging are running, it will
// cause a data race, therefore only initialize logging on the first call. From a main program, there is
// only one ServerContext.
if serverContextLoggingInitialized.CompareAndSwap(false, true) {
// cause a data race, therefore only initialize logging and other globals on the first call. From a main
// program, there is only one ServerContext.
if serverContextGlobalsInitialized.CompareAndSwap(false, true) {
// Logging config will now have been loaded from command line
// or from a sync_gateway config file so we can validate the
// configuration and setup logging now
Expand All @@ -1362,17 +1362,17 @@ func SetupServerContext(ctx context.Context, config *StartupConfig, persistentCo
log.Printf("[ERR] Error setting up logging: %v", err)
return nil, fmt.Errorf("error setting up logging: %v", err)
}
base.FlushLoggerBuffers()

if err := setGlobalConfig(ctx, config); err != nil {
return nil, err
}
}
base.FlushLoggerBuffers()

base.InfofCtx(ctx, base.KeyAll, "Logging: Console level: %v", base.ConsoleLogLevel())
base.InfofCtx(ctx, base.KeyAll, "Logging: Console keys: %v", base.ConsoleLogKey().EnabledLogKeys())
base.InfofCtx(ctx, base.KeyAll, "Logging: Redaction level: %s", config.Logging.RedactionLevel)

if err := setGlobalConfig(ctx, config); err != nil {
return nil, err
}

if err := config.Validate(ctx, base.IsEnterpriseEdition()); err != nil {
return nil, err
}
Expand Down

0 comments on commit 0b0675e

Please sign in to comment.