Browse Source

Fix logfile open filemode (#5354)

Fixes #5346
pull/5361/head
Simone Di Maulo 6 years ago committed by Matt Keeler
parent
commit
2aa516fd64
  1. 2
      logger/logfile.go
  2. 15
      logger/logfile_test.go

2
logger/logfile.go

@ -54,7 +54,7 @@ func (l *LogFile) openNew() error {
newfileName := fileName + "-" + strconv.FormatInt(createTime.UnixNano(), 10) + fileExt
newfilePath := filepath.Join(l.logPath, newfileName)
// Try creating a file. We truncate the file because we are the only authority to write the logs
filePointer, err := os.OpenFile(newfilePath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 640)
filePointer, err := os.OpenFile(newfilePath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0640)
if err != nil {
return err
}

15
logger/logfile_test.go

@ -29,6 +29,21 @@ func TestLogFile_timeRotation(t *testing.T) {
}
}
func TestLogFile_openNew(t *testing.T) {
t.Parallel()
tempDir := testutil.TempDir(t, "LogWriterOpen")
defer os.Remove(tempDir)
logFile := LogFile{fileName: testFileName, logPath: tempDir, duration: testDuration}
if err := logFile.openNew(); err != nil {
t.Errorf("Expected open file %s, got an error (%s)", testFileName, err)
}
if _, err := ioutil.ReadFile(logFile.FileInfo.Name()); err != nil {
t.Errorf("Expected readable file %s, got an error (%s)", logFile.FileInfo.Name(), err)
}
}
func TestLogFile_byteRotation(t *testing.T) {
t.Parallel()
tempDir := testutil.TempDir(t, "LogWriterBytes")

Loading…
Cancel
Save