chore_: remove endpoint InitLogging (#6182)

This commit is contained in:
frank 2024-12-10 09:19:08 +08:00 committed by GitHub
parent 4ccb08f11d
commit e6c2f89f03
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 0 additions and 78 deletions

View File

@ -1,47 +0,0 @@
package statusgo
import (
"fmt"
"os"
"path"
"testing"
"github.com/stretchr/testify/require"
"github.com/status-im/status-go/logutils/requestlog"
"github.com/status-im/status-go/protocol/requests"
)
func TestInitLogging(t *testing.T) {
tempDir := t.TempDir()
t.Logf("temp dir: %s", tempDir)
gethLogFile := path.Join(tempDir, "geth.log")
requestsLogFile := path.Join(tempDir, "requests.log")
logSettings := fmt.Sprintf(`{"LogRequestGo": true, "LogRequestFile": "%s", "File": "%s", "Level": "INFO", "Enabled": true, "MobileSystem": false}`, requestsLogFile, gethLogFile)
response := InitLogging(logSettings)
require.Equal(t, `{"error":""}`, response)
_, err := os.Stat(gethLogFile)
require.NoError(t, err)
require.NotNil(t, requestlog.GetRequestLogger())
// requests log file should not be created yet
_, err = os.Stat(requestsLogFile)
require.Error(t, err)
require.True(t, os.IsNotExist(err))
createAccountRequest := &requests.CreateAccount{
DisplayName: "some-display-name",
CustomizationColor: "#ffffff",
Password: "some-password",
RootDataDir: tempDir,
LogFilePath: gethLogFile,
}
_, err = statusBackend.CreateAccountAndLogin(createAccountRequest)
require.NoError(t, err)
result := CallPrivateRPC(`{"jsonrpc":"2.0","method":"settings_getSettings","params":[],"id":1}`)
require.NotContains(t, result, "error")
// Check if request log file exists now
_, err = os.Stat(requestsLogFile)
require.NoError(t, err)
require.FileExists(t, requestsLogFile)
}

View File

@ -2218,37 +2218,6 @@ func deserializeAndCompressKey(DesktopKey string) string {
return CompressPublicKey(sanitisedKey)
}
type InitLoggingRequest struct {
logutils.LogSettings
LogRequestGo bool `json:"LogRequestGo"`
LogRequestFile string `json:"LogRequestFile"`
}
// 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.
// Before this, we can only capture logs after user login since we will only configure the logging after the login process.
// Deprecated: Use InitializeApplication instead
func InitLogging(logSettingsJSON string) string {
var logSettings InitLoggingRequest
var err error
if err = json.Unmarshal([]byte(logSettingsJSON), &logSettings); err != nil {
return makeJSONResponse(err)
}
if err = logutils.OverrideRootLoggerWithConfig(logSettings.LogSettings); err == nil {
logutils.ZapLogger().Info("logging initialised", zap.String("logSettings", logSettingsJSON))
}
if logSettings.LogRequestGo {
err = requestlog.ConfigureAndEnableRequestLogging(logSettings.LogRequestFile)
if err != nil {
return makeJSONResponse(err)
}
}
return makeJSONResponse(err)
}
func GetRandomMnemonic() string {
mnemonic, err := account.GetRandomMnemonic()
if err != nil {