From 72ff69d9bb61d532e776ffdf46a32b75c9bbbd43 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Thu, 9 May 2024 14:29:37 -0700 Subject: [PATCH] add log-prefix name for specifying custom log-name (#19712) --- cmd/server-main.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cmd/server-main.go b/cmd/server-main.go index 37a1ebcb6..49071c411 100644 --- a/cmd/server-main.go +++ b/cmd/server-main.go @@ -212,6 +212,12 @@ var ServerFlags = []cli.Flag{ EnvVar: "MINIO_LOG_COMPRESS", Hidden: true, }, + cli.StringFlag{ + Name: "log-prefix", + Usage: "specify the log prefix name for the server log", + EnvVar: "MINIO_LOG_PREFIX", + Hidden: true, + }, } var serverCmd = cli.Command{ @@ -737,10 +743,19 @@ func initializeLogRotate(ctx *cli.Context) (io.WriteCloser, error) { return nil, err } lgSize := ctx.Int("log-size") + + var fileNameFunc func() string + if ctx.IsSet("log-prefix") { + fileNameFunc = func() string { + return fmt.Sprintf("%s-%s.log", ctx.String("log-prefix"), fmt.Sprintf("%X", time.Now().UTC().UnixNano())) + } + } + output, err := logger.NewDir(logger.Options{ Directory: lgDirAbs, MaximumFileSize: int64(lgSize), Compress: ctx.Bool("log-compress"), + FileNameFunc: fileNameFunc, }) if err != nil { return nil, err