add InitLogging (#3643)

* add InitLogging

* addressed feedback from @Samyoul
This commit is contained in:
frank 2023-06-21 21:04:43 +08:00 committed by GitHub
parent 2fb87b5f0d
commit 1d5ffc0ba0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

@ -1 +1 @@
0.159.2
0.159.3

View File

@ -6,8 +6,11 @@ import (
"errors"
"fmt"
"os"
"sync"
"unsafe"
"github.com/status-im/status-go/logutils"
validator "gopkg.in/go-playground/validator.v9"
"github.com/ethereum/go-ethereum/log"
@ -1239,3 +1242,24 @@ func DeserializeAndCompressKey(DesktopKey string) string {
sanitisedKey := "0x" + deserialisedKey[5:]
return CompressPublicKey(sanitisedKey)
}
var initLoggingOnce sync.Once
// 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.
func InitLogging(logSettingsJSON string) string {
var logSettings logutils.LogSettings
var err error
if err = json.Unmarshal([]byte(logSettingsJSON), &logSettings); err != nil {
return makeJSONResponse(err)
}
initLoggingOnce.Do(func() {
if err = logutils.OverrideRootLogWithConfig(logSettings, false); err == nil {
log.Info("logging initialised", "logSettings", logSettingsJSON)
}
})
return makeJSONResponse(err)
}