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. 3
      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() { func main() {
ip := flag.String("ip", "127.0.0.1", "IP of the node") ip := flag.String("ip", "127.0.0.1", "IP of the node")
port := flag.String("port", "9876", "port 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") 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") 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") 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 // Logging setup
utils.SetLogContext(*port, *ip) utils.SetLogContext(*port, *ip)
utils.SetLogVerbosity(log.Lvl(*verbosity)) utils.SetLogVerbosity(log.Lvl(*verbosity))
if *console != true {
utils.AddLogFile(fmt.Sprintf("%v/bootnode-%v-%v.log", *logFolder, *ip, *port), *logMaxSize, *logRotateCount, *logRotateMaxAge) utils.AddLogFile(fmt.Sprintf("%v/bootnode-%v-%v.log", *logFolder, *ip, *port), *logMaxSize, *logRotateCount, *logRotateMaxAge)
}
privKey, _, err := utils.LoadKeyFromFile(*keyFile) privKey, _, err := utils.LoadKeyFromFile(*keyFile)
if err != nil { if err != nil {

@ -274,4 +274,12 @@ func init() {
return confTree 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 Port = 9500
[Log] [Log]
Console = false
FileName = "harmony.log" FileName = "harmony.log"
Folder = "./latest" Folder = "./latest"
RotateSize = 100 RotateSize = 100

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

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

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

@ -246,18 +246,18 @@ func applyRootFlags(cmd *cobra.Command, config *harmonyconfig.HarmonyConfig) {
func setupNodeLog(config harmonyconfig.HarmonyConfig) { func setupNodeLog(config harmonyconfig.HarmonyConfig) {
logPath := filepath.Join(config.Log.Folder, config.Log.FileName) 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 verbosity := config.Log.Verbosity
utils.AddLogFile(logPath, rotateSize, rotateCount, rotateMaxAge)
utils.SetLogVerbosity(log.Lvl(verbosity)) utils.SetLogVerbosity(log.Lvl(verbosity))
if config.Log.Context != nil { if config.Log.Context != nil {
ip := config.Log.Context.IP ip := config.Log.Context.IP
port := config.Log.Context.Port port := config.Log.Context.Port
utils.SetLogContext(ip, strconv.Itoa(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) { func setupNodeAndRun(hc harmonyconfig.HarmonyConfig) {

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

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

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

Loading…
Cancel
Save