feat: make log to console as optional (#4208)

* fix: add option for console only

Signed-off-by: Jason Yi <jasonhk.yi@consensys.net>

* fix: add console option for node & harmony

Signed-off-by: Jason Yi <jasonhk.yi@consensys.net>

* fix: add console to default config

Signed-off-by: Jason Yi <jasonhk.yi@consensys.net>

* fix: remove debugging code

Signed-off-by: Jason Yi <jasonhk.yi@consensys.net>

* fix: add log.console to cmd line options

Signed-off-by: Jason Yi <jasonhk.yi@consensys.net>

* fix: linting & revert back msg.pg.go

Signed-off-by: Jason Yi <jasonhk.yi@consensys.net>

* undo changes in go.sum

Signed-off-by: Jason Yi <jasonhk.yi@consensys.net>

* update: config migration

Signed-off-by: Jason Yi <jasonhk.yi@consensys.net>
pull/4254/head
Jason Yi 2 years ago committed by GitHub
parent f7cadd9db0
commit a928fe4ab7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      cmd/bootnode/main.go
  2. 8
      cmd/harmony/config_migrations.go
  3. 1
      cmd/harmony/config_test.go
  4. 1
      cmd/harmony/default.go
  5. 10
      cmd/harmony/flags.go
  6. 2
      cmd/harmony/flags_test.go
  7. 8
      cmd/harmony/main.go
  8. 1
      internal/configs/harmony/harmony.go
  9. 1
      rosetta/infra/harmony-mainnet.conf
  10. 1
      rosetta/infra/harmony-pstn.conf

@ -92,6 +92,7 @@ func printVersion(me string) {
func main() {
ip := flag.String("ip", "127.0.0.1", "IP of the node")
port := flag.String("port", "9876", "port of the node.")
console := flag.Bool("console_only", false, "Output to console only")
logFolder := flag.String("log_folder", "latest", "the folder collecting the logs of this execution")
logMaxSize := flag.Int("log_max_size", 100, "the max size in megabytes of the log file before it gets rotated")
logRotateCount := flag.Int("log_rotate_count", 0, "the number of rotated logs to keep. If set to 0 rotation is disabled")
@ -111,7 +112,9 @@ func main() {
// Logging setup
utils.SetLogContext(*port, *ip)
utils.SetLogVerbosity(log.Lvl(*verbosity))
utils.AddLogFile(fmt.Sprintf("%v/bootnode-%v-%v.log", *logFolder, *ip, *port), *logMaxSize, *logRotateCount, *logRotateMaxAge)
if *console != true {
utils.AddLogFile(fmt.Sprintf("%v/bootnode-%v-%v.log", *logFolder, *ip, *port), *logMaxSize, *logRotateCount, *logRotateMaxAge)
}
privKey, _, err := utils.LoadKeyFromFile(*keyFile)
if err != nil {

@ -274,4 +274,12 @@ func init() {
return confTree
}
migrations["2.5.3"] = func(confTree *toml.Tree) *toml.Tree {
if confTree.Get("Log.Console") == nil {
confTree.Set("Log.Console", defaultConfig.Log.Console)
}
confTree.Set("Version", "2.5.4")
return confTree
}
}

@ -59,6 +59,7 @@ Version = "1.0.4"
Port = 9500
[Log]
Console = false
FileName = "harmony.log"
Folder = "./latest"
RotateSize = 100

@ -86,6 +86,7 @@ var defaultConfig = harmonyconfig.HarmonyConfig{
ProfileDebugValues: []int{0},
},
Log: harmonyconfig.LogConfig{
Console: false,
Folder: "./latest",
FileName: "harmony.log",
RotateSize: 100,

@ -159,6 +159,7 @@ var (
logVerbosityFlag,
logVerbosePrintsFlag,
legacyVerbosityFlag,
logConsoleFlag,
legacyLogFolderFlag,
legacyLogRotateSizeFlag,
@ -1229,6 +1230,11 @@ var (
Usage: "debugging feature. to print verbose internal objects as JSON in log file. available internal objects: config",
DefValue: []string{"config"},
}
logConsoleFlag = cli.BoolFlag{
Name: "log.console",
Usage: "output log to console only",
DefValue: defaultConfig.Log.Console,
}
// TODO: remove context (this shall not be in the log)
logContextIPFlag = cli.StringFlag{
Name: "log.ctx.ip",
@ -1298,6 +1304,10 @@ func applyLogFlags(cmd *cobra.Command, config *harmonyconfig.HarmonyConfig) {
config.Log.VerbosePrints = harmonyconfig.FlagSliceToLogVerbosePrints(verbosePrintsFlagSlice)
}
if cli.IsFlagChanged(cmd, logConsoleFlag) {
config.Log.Console = cli.GetBoolFlagValue(cmd, logConsoleFlag)
}
if cli.HasFlagsChanged(cmd, []cli.Flag{logContextIPFlag, logContextPortFlag}) {
ctx := getDefaultLogContextCopy()
config.Log.Context = &ctx

@ -121,6 +121,7 @@ func TestHarmonyFlags(t *testing.T) {
ProfileDebugValues: []int{0},
},
Log: harmonyconfig.LogConfig{
Console: false,
Folder: "./latest",
FileName: "validator-8.8.8.8-9000.log",
RotateSize: 100,
@ -1082,6 +1083,7 @@ func TestLogFlags(t *testing.T) {
{
args: []string{"--log.ctx.ip", "8.8.8.8", "--log.ctx.port", "9001"},
expConfig: harmonyconfig.LogConfig{
Console: defaultConfig.Log.Console,
Folder: defaultConfig.Log.Folder,
FileName: defaultConfig.Log.FileName,
RotateSize: defaultConfig.Log.RotateSize,

@ -246,18 +246,18 @@ func applyRootFlags(cmd *cobra.Command, config *harmonyconfig.HarmonyConfig) {
func setupNodeLog(config harmonyconfig.HarmonyConfig) {
logPath := filepath.Join(config.Log.Folder, config.Log.FileName)
rotateSize := config.Log.RotateSize
rotateCount := config.Log.RotateCount
rotateMaxAge := config.Log.RotateMaxAge
verbosity := config.Log.Verbosity
utils.AddLogFile(logPath, rotateSize, rotateCount, rotateMaxAge)
utils.SetLogVerbosity(log.Lvl(verbosity))
if config.Log.Context != nil {
ip := config.Log.Context.IP
port := config.Log.Context.Port
utils.SetLogContext(ip, strconv.Itoa(port))
}
if config.Log.Console != true {
utils.AddLogFile(logPath, config.Log.RotateSize, config.Log.RotateCount, config.Log.RotateMaxAge)
}
}
func setupNodeAndRun(hc harmonyconfig.HarmonyConfig) {

@ -128,6 +128,7 @@ type PprofConfig struct {
}
type LogConfig struct {
Console bool
Folder string
FileName string
RotateSize int

@ -45,6 +45,7 @@ Version = "2.5.5"
RosettaPort = 9700
[Log]
Console = false
FileName = "harmony.log"
Folder = "./latest"
RotateCount = 0

@ -45,6 +45,7 @@ Version = "2.5.4"
RosettaPort = 9700
[Log]
Console = false
FileName = "harmony.log"
Folder = "./latest"
RotateCount = 0

Loading…
Cancel
Save