mirror of https://github.com/status-im/consul.git
parent
c8a1acd508
commit
2aa516fd64
|
@ -54,7 +54,7 @@ func (l *LogFile) openNew() error {
|
||||||
newfileName := fileName + "-" + strconv.FormatInt(createTime.UnixNano(), 10) + fileExt
|
newfileName := fileName + "-" + strconv.FormatInt(createTime.UnixNano(), 10) + fileExt
|
||||||
newfilePath := filepath.Join(l.logPath, newfileName)
|
newfilePath := filepath.Join(l.logPath, newfileName)
|
||||||
// Try creating a file. We truncate the file because we are the only authority to write the logs
|
// 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
func TestLogFile_byteRotation(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
tempDir := testutil.TempDir(t, "LogWriterBytes")
|
tempDir := testutil.TempDir(t, "LogWriterBytes")
|
||||||
|
|
Loading…
Reference in New Issue