From 98f301e30b24d359be00e4e00470073e25054516 Mon Sep 17 00:00:00 2001 From: JARDEL ALVES Date: Wed, 18 Mar 2026 10:59:22 -0300 Subject: [PATCH] glog: add --log_max_size_mb and --log_max_files runtime flags (#8684) --- weed/glog/glog_file.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/weed/glog/glog_file.go b/weed/glog/glog_file.go index eef89802a..f91acf82a 100644 --- a/weed/glog/glog_file.go +++ b/weed/glog/glog_file.go @@ -33,7 +33,11 @@ import ( ) // MaxSize is the maximum size of a log file in bytes. +// It is initialized from the --log_max_size_mb flag when the first log file is created. var MaxSize uint64 = 1024 * 1024 * 1800 + +// MaxFileCount is the maximum number of log files retained per severity level. +// It is initialized from the --log_max_files flag when the first log file is created. var MaxFileCount = 5 // logDirs lists the candidate directories for new log files. @@ -43,7 +47,25 @@ var logDirs []string // See createLogDirs for the full list of possible destinations. var logDir = flag.String("logdir", "", "If non-empty, write log files in this directory") +// logMaxSizeMB controls the maximum size of each log file in megabytes. +// When a log file reaches this size it is closed and a new file is created. +// Defaults to 1800 MB. Set to 0 to use the compiled-in default. +var logMaxSizeMB = flag.Uint64("log_max_size_mb", 1800, "Maximum size in megabytes of each log file before it is rotated (0 = use default of 1800 MB)") + +// logMaxFiles controls how many log files are kept per severity level. +// Older files are deleted when the limit is exceeded. +// Defaults to 5. +var logMaxFiles = flag.Int("log_max_files", 5, "Maximum number of log files to keep per severity level before older ones are deleted (0 = use default of 5)") + func createLogDirs() { + // Apply flag values now that flags have been parsed. + if *logMaxSizeMB > 0 { + MaxSize = *logMaxSizeMB * 1024 * 1024 + } + if *logMaxFiles > 0 { + MaxFileCount = *logMaxFiles + } + if *logDir != "" { logDirs = append(logDirs, *logDir) } else {