add log-prefix name for specifying custom log-name (#19712)

This commit is contained in:
Harshavardhana 2024-05-09 14:29:37 -07:00 committed by GitHub
parent f30417d9a8
commit 72ff69d9bb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 15 additions and 0 deletions

View File

@ -212,6 +212,12 @@ var ServerFlags = []cli.Flag{
EnvVar: "MINIO_LOG_COMPRESS", EnvVar: "MINIO_LOG_COMPRESS",
Hidden: true, 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{ var serverCmd = cli.Command{
@ -737,10 +743,19 @@ func initializeLogRotate(ctx *cli.Context) (io.WriteCloser, error) {
return nil, err return nil, err
} }
lgSize := ctx.Int("log-size") 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{ output, err := logger.NewDir(logger.Options{
Directory: lgDirAbs, Directory: lgDirAbs,
MaximumFileSize: int64(lgSize), MaximumFileSize: int64(lgSize),
Compress: ctx.Bool("log-compress"), Compress: ctx.Bool("log-compress"),
FileNameFunc: fileNameFunc,
}) })
if err != nil { if err != nil {
return nil, err return nil, err