handle create/open file error

remotes/origin/HEAD
fangdingjun 7 years ago
parent 41879e9ec2
commit ca8ca518a5

@ -22,7 +22,9 @@ type AlwaysNewFileWriter struct {
// Write implements io.Writer // Write implements io.Writer
func (w *AlwaysNewFileWriter) Write(p []byte) (n int, err error) { func (w *AlwaysNewFileWriter) Write(p []byte) (n int, err error) {
if w.file == nil { if w.file == nil {
w.openFile() if err = w.openFile(); err != nil {
return
}
} }
return w.file.Write(p) return w.file.Write(p)

@ -25,10 +25,14 @@ func (w *DailyFileWriter) Write(p []byte) (n int, err error) {
now := time.Now() now := time.Now()
if w.file == nil { if w.file == nil {
w.openFile(&now) if err = w.openFile(&now); err != nil {
return
}
} else if now.Unix() >= w.nextDayTime { } else if now.Unix() >= w.nextDayTime {
w.file.Close() w.file.Close()
w.openFile(&now) if err = w.openFile(&now); err != nil {
return
}
} }
return w.file.Write(p) return w.file.Write(p)

@ -20,10 +20,16 @@ type FixedSizeFileWriter struct {
// Write implements io.Writer // Write implements io.Writer
func (w *FixedSizeFileWriter) Write(p []byte) (n int, err error) { func (w *FixedSizeFileWriter) Write(p []byte) (n int, err error) {
if w.file == nil { if w.file == nil {
w.openCurrentFile() if err = w.openCurrentFile(); err != nil {
} else if w.currentSize > w.MaxSize { return
}
}
if w.currentSize > w.MaxSize {
w.file.Close() w.file.Close()
w.openNextFile() if err = w.openNextFile(); err != nil {
return
}
} }
w.currentSize += int64(len(p)) w.currentSize += int64(len(p))

Loading…
Cancel
Save