diff --git a/app/server.go b/app/server.go index cc6baba532..c829dc5885 100644 --- a/app/server.go +++ b/app/server.go @@ -184,7 +184,6 @@ func NewServer(options ...Option) (*Server, error) { hashSeed: maphash.MakeSeed(), } - mlog.Info("Server is initializing...") for _, option := range options { if err := option(s); err != nil { return nil, errors.Wrap(err, "failed to apply option") @@ -204,6 +203,9 @@ func NewServer(options ...Option) (*Server, error) { mlog.Error(err.Error()) } + // This is called after initLogging() to avoid a race condition. + mlog.Info("Server is initializing...") + // It is important to initialize the hub only after the global logger is set // to avoid race conditions while logging from inside the hub. fakeApp := New(ServerConnector(s)) diff --git a/mlog/testing.go b/mlog/testing.go index f66c0f4d45..1f2f437fac 100644 --- a/mlog/testing.go +++ b/mlog/testing.go @@ -35,7 +35,7 @@ func NewTestingLogger(tb testing.TB, writer io.Writer) *Logger { logrLogger: newLogr(), } - logWriterCore := zapcore.NewCore(makeEncoder(true), logWriterSync, testingLogger.consoleLevel) + logWriterCore := zapcore.NewCore(makeEncoder(true), zapcore.Lock(logWriterSync), testingLogger.consoleLevel) testingLogger.zap = zap.New(logWriterCore, zap.AddCaller(),