Skip to content

Commit

Permalink
Fix logfile open filemode (#5354)
Browse files Browse the repository at this point in the history
Fixes #5346
  • Loading branch information
simodima authored and mkeeler committed Feb 15, 2019
1 parent c8a1acd commit 2aa516f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion logger/logfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
15 changes: 15 additions & 0 deletions logger/logfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 2aa516f

Please sign in to comment.