Skip to content

Commit

Permalink
[status-im/status-mobile#9942] relative paths
Browse files Browse the repository at this point in the history
  • Loading branch information
rasom committed Jan 31, 2020
1 parent c2f22f1 commit 4934cca
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 8 deletions.
7 changes: 5 additions & 2 deletions api/geth_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (b *GethStatusBackend) startNodeWithKey(acc multiaccounts.Account, password
if err != nil {
return err
}
if err := logutils.OverrideRootLogWithConfig(conf, false); err != nil {
if err := logutils.OverrideRootLogWithConfig(conf, b.rootDataDir, false); err != nil {
return err
}
accountsDB := accounts.NewDB(b.appDB)
Expand Down Expand Up @@ -261,7 +261,7 @@ func (b *GethStatusBackend) startNodeWithAccount(acc multiaccounts.Account, pass
if err != nil {
return err
}
if err := logutils.OverrideRootLogWithConfig(conf, false); err != nil {
if err := logutils.OverrideRootLogWithConfig(conf, b.rootDataDir, false); err != nil {
return err
}
accountsDB := accounts.NewDB(b.appDB)
Expand Down Expand Up @@ -442,6 +442,9 @@ func (b *GethStatusBackend) startNode(config *params.NodeConfig) (err error) {
if manager == nil {
return errors.New("ethereum accounts.Manager is nil")
}

config.DataDir = filepath.Join(b.rootDataDir, config.DataDir)
config.KeyStoreDir = filepath.Join(b.rootDataDir, config.KeyStoreDir)
if err = b.statusNode.StartWithOptions(config, node.StartOptions{
Services: services,
// The peers discovery protocols are started manually after
Expand Down
4 changes: 2 additions & 2 deletions api/nimbus_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func (b *nimbusStatusBackend) startNodeWithKey(acc multiaccounts.Account, passwo
if err != nil {
return err
}
if err := logutils.OverrideRootLogWithConfig(conf, false); err != nil {
if err := logutils.OverrideRootLogWithConfig(conf, b.rootDataDir, false); err != nil {
return err
}
accountsDB := accounts.NewDB(b.appDB)
Expand Down Expand Up @@ -255,7 +255,7 @@ func (b *nimbusStatusBackend) startNodeWithAccount(acc multiaccounts.Account, pa
if err != nil {
return err
}
if err := logutils.OverrideRootLogWithConfig(conf, false); err != nil {
if err := logutils.OverrideRootLogWithConfig(conf, b.rootDataDir, false); err != nil {
return err
}
accountsDB := accounts.NewDB(b.appDB)
Expand Down
2 changes: 1 addition & 1 deletion cmd/statusd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func setupLogging(config *params.NodeConfig) {
}

colors := !(*logWithoutColors) && terminal.IsTerminal(int(os.Stdin.Fd()))
if err := logutils.OverrideRootLogWithConfig(config, colors); err != nil {
if err := logutils.OverrideRootLogWithConfig(config, "", colors); err != nil {
stdlog.Fatalf("Error initializing logger: %v", err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func StartNode(configJSON *C.char) *C.char {
return makeJSONResponse(err)
}

if err := logutils.OverrideRootLogWithConfig(config, false); err != nil {
if err := logutils.OverrideRootLogWithConfig(config, statusBackend.rootDataDir, false); err != nil {
return makeJSONResponse(err)
}

Expand Down
13 changes: 11 additions & 2 deletions logutils/override.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package logutils

import (
"os"
"path/filepath"
"strings"

"github.com/ethereum/go-ethereum/log"
Expand All @@ -15,15 +16,23 @@ func OverrideWithStdLogger(config *params.NodeConfig) error {
}

// OverrideRootLogWithConfig derives all configuration from params.NodeConfig and configures logger using it.
func OverrideRootLogWithConfig(config *params.NodeConfig, colors bool) error {
func OverrideRootLogWithConfig(config *params.NodeConfig, rootDataDir string, colors bool) error {
if !config.LogEnabled {
return nil
}
if config.LogMobileSystem {
return OverrideWithStdLogger(config)
}

var logFile string
if len(config.LogDir) == 0 {
logFile = filepath.Join(rootDataDir, config.LogFile)
} else {
logFile = filepath.Join(config.LogDir, config.LogFile)
}

return OverrideRootLog(config.LogEnabled, config.LogLevel, FileOptions{
Filename: config.LogFile,
Filename: logFile,
MaxSize: config.LogMaxSize,
MaxBackups: config.LogMaxBackups,
Compress: config.LogCompressRotated,
Expand Down
3 changes: 3 additions & 0 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ type NodeConfig struct {
// LogMobileSystem enables log redirection to android/ios system logger.
LogMobileSystem bool

// LogFile is a folder which contains LogFile
LogDir string

// LogFile is filename where exposed logs get written to
LogFile string

Expand Down

0 comments on commit 4934cca

Please sign in to comment.