From ee5b881e1062da6c24ff0edff107f25408721887 Mon Sep 17 00:00:00 2001 From: vegbir Date: Tue, 8 Aug 2023 11:43:55 +0800 Subject: [PATCH] modify the mode of dump log to 400 Signed-off-by: vegbir --- pkg/common/constant/constant.go | 2 ++ pkg/common/log/log.go | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/common/constant/constant.go b/pkg/common/constant/constant.go index 2df0b81..6a1f69d 100644 --- a/pkg/common/constant/constant.go +++ b/pkg/common/constant/constant.go @@ -48,6 +48,8 @@ const ( DefaultFileMode os.FileMode = 0600 // DefaultDirMode is dir default mode DefaultDirMode os.FileMode = 0700 + // DefaultDumpLogFileMode is the permission of the log file (recorded or archived) + DefaultDumpLogFileMode os.FileMode = 0400 ) // Pod Annotation diff --git a/pkg/common/log/log.go b/pkg/common/log/log.go index bda812f..fc0b9b8 100644 --- a/pkg/common/log/log.go +++ b/pkg/common/log/log.go @@ -160,6 +160,7 @@ func levelFromString(level string) (int, error) { } func renameLogFile() { + // rename the log that is no longer recorded, that is, the log of rubik.log.X for i := logFileNum - 1; i > 1; i-- { oldFile := logFname + fmt.Sprintf(".%d", i-1) newFile := logFname + fmt.Sprintf(".%d", i) @@ -167,7 +168,12 @@ func renameLogFile() { DropError(os.Rename(oldFile, newFile)) } } - DropError(os.Rename(logFname, logFname+".1")) + + // dump the current rubik log + firstDumpLogName := logFname + ".1" + DropError(os.Rename(logFname, firstDumpLogName)) + // change log file permissions + DropError(os.Chmod(firstDumpLogName, constant.DefaultDumpLogFileMode)) } func rotateLog(line int64) string { -- Gitee