| 195 | } |
| 196 | |
| 197 | func (l *LogWriter) rotate() error { |
| 198 | if l == nil { |
| 199 | return nil |
| 200 | } |
| 201 | |
| 202 | l.flush() |
| 203 | if err := l.file.Close(); err != nil { |
| 204 | return err |
| 205 | } |
| 206 | |
| 207 | if _, err := os.Stat(l.FilePath); err == nil { |
| 208 | // move the existing file |
| 209 | newname := backupName(l.FilePath) |
| 210 | if err := os.Rename(l.FilePath, newname); err != nil { |
| 211 | return fmt.Errorf("can't rename log file: %s", err) |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | l.manageChannel <- true |
| 216 | return l.open() |
| 217 | } |
| 218 | |
| 219 | func (l *LogWriter) open() error { |
| 220 | if l == nil { |