Browse Source

glog: add --log_max_size_mb and --log_max_files runtime flags (#8684)

pull/8687/head
JARDEL ALVES 3 days ago
committed by GitHub
parent
commit
98f301e30b
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 22
      weed/glog/glog_file.go

22
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 {

Loading…
Cancel
Save