diff --git a/cmd/bootnode/main.go b/cmd/bootnode/main.go index 6381a66b7..f0da1879a 100644 --- a/cmd/bootnode/main.go +++ b/cmd/bootnode/main.go @@ -32,20 +32,24 @@ func printVersion(me string) { os.Exit(0) } -func initLogFile(logFolder, ip, port string) { +func initLogFile(logFolder, ip, port string, logMaxSize int) { // Setup a logger to stdout and log file. if err := os.MkdirAll(logFolder, 0755); err != nil { panic(err) } - logFileName := fmt.Sprintf("./%v/bootnode-%v-%v.log", logFolder, ip, port) - fileHandler := log.Must.FileHandler(logFileName, log.JSONFormat()) // Log to file - utils.AddLogHandler(fileHandler) + utils.AddLogHandler( + log.StreamHandler(&lumberjack.Logger{ + Filename: fmt.Sprintf("./%v/bootnode-%v-%v.log", logFolder, ip, port), + MaxSize: logMaxSize, + Compress: true, + }, log.JSONFormat())) } func main() { ip := flag.String("ip", "127.0.0.1", "IP of the node") port := flag.String("port", "9876", "port of the node.") 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") keyFile := flag.String("key", "./.bnkey", "the private key file of the bootnode") versionFlag := flag.Bool("version", false, "Output version info") verbosity := flag.Int("verbosity", 5, "Logging verbosity: 0=silent, 1=error, 2=warn, 3=info, 4=debug, 5=detail (default: 5)") @@ -60,7 +64,7 @@ func main() { // Logging setup utils.SetLogContext(*port, *ip) utils.SetLogVerbosity(log.Lvl(*verbosity)) - initLogFile(*logFolder, *ip, *port) + initLogFile(*logFolder, *ip, *port, *logMaxSize) privKey, _, err := utils.LoadKeyFromFile(*keyFile) if err != nil {