Rotate log files in bootnode cmd

pull/1173/head
Kai Lee 5 years ago
parent d1f812457f
commit f334a1d8fa
  1. 14
      cmd/bootnode/main.go

@ -32,20 +32,24 @@ func printVersion(me string) {
os.Exit(0) 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. // Setup a logger to stdout and log file.
if err := os.MkdirAll(logFolder, 0755); err != nil { if err := os.MkdirAll(logFolder, 0755); err != nil {
panic(err) panic(err)
} }
logFileName := fmt.Sprintf("./%v/bootnode-%v-%v.log", logFolder, ip, port) utils.AddLogHandler(
fileHandler := log.Must.FileHandler(logFileName, log.JSONFormat()) // Log to file log.StreamHandler(&lumberjack.Logger{
utils.AddLogHandler(fileHandler) Filename: fmt.Sprintf("./%v/bootnode-%v-%v.log", logFolder, ip, port),
MaxSize: logMaxSize,
Compress: true,
}, log.JSONFormat()))
} }
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.")
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")
keyFile := flag.String("key", "./.bnkey", "the private key file of the bootnode") keyFile := flag.String("key", "./.bnkey", "the private key file of the bootnode")
versionFlag := flag.Bool("version", false, "Output version info") 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)") 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 // Logging setup
utils.SetLogContext(*port, *ip) utils.SetLogContext(*port, *ip)
utils.SetLogVerbosity(log.Lvl(*verbosity)) utils.SetLogVerbosity(log.Lvl(*verbosity))
initLogFile(*logFolder, *ip, *port) initLogFile(*logFolder, *ip, *port, *logMaxSize)
privKey, _, err := utils.LoadKeyFromFile(*keyFile) privKey, _, err := utils.LoadKeyFromFile(*keyFile)
if err != nil { if err != nil {

Loading…
Cancel
Save