Move log creation mutexes up a level to prevent races in unit tests

This commit is contained in:
Devon Hudson 2023-01-23 10:35:19 -07:00
parent 7900bfeb52
commit eae2db401b
No known key found for this signature in database
GPG key ID: CD06B18E77F6A628
2 changed files with 4 additions and 2 deletions

View file

@ -101,6 +101,8 @@ func SetupPprof() {
// SetupStdLogging configures the logging format to standard output. Typically, it is called when the config is not yet loaded. // SetupStdLogging configures the logging format to standard output. Typically, it is called when the config is not yet loaded.
func SetupStdLogging() { func SetupStdLogging() {
levelLogAddedMu.Lock()
defer levelLogAddedMu.Unlock()
logrus.SetReportCaller(true) logrus.SetReportCaller(true)
logrus.SetFormatter(&utcFormatter{ logrus.SetFormatter(&utcFormatter{
&logrus.TextFormatter{ &logrus.TextFormatter{

View file

@ -32,6 +32,8 @@ import (
// If something fails here it means that the logging was improperly configured, // If something fails here it means that the logging was improperly configured,
// so we just exit with the error // so we just exit with the error
func SetupHookLogging(hooks []config.LogrusHook, componentName string) { func SetupHookLogging(hooks []config.LogrusHook, componentName string) {
levelLogAddedMu.Lock()
defer levelLogAddedMu.Unlock()
for _, hook := range hooks { for _, hook := range hooks {
// Check we received a proper logging level // Check we received a proper logging level
level, err := logrus.ParseLevel(hook.Level) level, err := logrus.ParseLevel(hook.Level)
@ -85,8 +87,6 @@ func checkSyslogHookParams(params map[string]interface{}) {
} }
func setupStdLogHook(level logrus.Level) { func setupStdLogHook(level logrus.Level) {
levelLogAddedMu.Lock()
defer levelLogAddedMu.Unlock()
if stdLevelLogAdded[level] { if stdLevelLogAdded[level] {
return return
} }