fix_: remove the restriction to call InitLogging only once

This commit is contained in:
Volodymyr Kozieiev 2024-08-07 12:52:06 +01:00 committed by Andrea Maria Piana
parent 085d0228aa
commit 60d00e8fe8

View File

@ -6,7 +6,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"os" "os"
"sync"
"unsafe" "unsafe"
validator "gopkg.in/go-playground/validator.v9" validator "gopkg.in/go-playground/validator.v9"
@ -1401,10 +1400,8 @@ func DeserializeAndCompressKey(DesktopKey string) string {
return CompressPublicKey(sanitisedKey) return CompressPublicKey(sanitisedKey)
} }
var initLoggingOnce sync.Once // InitLogging The InitLogging function should be called when the application starts.
// This ensures that we can capture logs before the user login. Subsequent calls will update the logger settings.
// InitLogging The InitLogging function should be called only once during the application's lifetime,
// specifically when the application starts. This ensures that we can capture logs before the user login.
// Before this, we can only capture logs after user login since we will only configure the logging after the login process. // Before this, we can only capture logs after user login since we will only configure the logging after the login process.
func InitLogging(logSettingsJSON string) string { func InitLogging(logSettingsJSON string) string {
var logSettings logutils.LogSettings var logSettings logutils.LogSettings
@ -1413,11 +1410,9 @@ func InitLogging(logSettingsJSON string) string {
return makeJSONResponse(err) return makeJSONResponse(err)
} }
initLoggingOnce.Do(func() { if err = logutils.OverrideRootLogWithConfig(logSettings, false); err == nil {
if err = logutils.OverrideRootLogWithConfig(logSettings, false); err == nil { log.Info("logging initialised", "logSettings", logSettingsJSON)
log.Info("logging initialised", "logSettings", logSettingsJSON) }
}
})
return makeJSONResponse(err) return makeJSONResponse(err)
} }