| 355 | } |
| 356 | |
| 357 | func (r *rotatedFile) Write(bs []byte) (int, error) { |
| 358 | // Check if we're about to exceed the max size, and if so close this |
| 359 | // file so we'll start on a new one. |
| 360 | if r.currentSize+int64(len(bs)) > r.maxSize { |
| 361 | r.currentFile.Close() |
| 362 | r.currentSize = 0 |
| 363 | r.rotate() |
| 364 | f, err := r.create(r.name) |
| 365 | if err != nil { |
| 366 | return 0, err |
| 367 | } |
| 368 | r.currentFile = f |
| 369 | } |
| 370 | |
| 371 | n, err := r.currentFile.Write(bs) |
| 372 | r.currentSize += int64(n) |
| 373 | return n, err |
| 374 | } |
| 375 | |
| 376 | func (r *rotatedFile) rotate() { |
| 377 | // The files are named "name", "name.0", "name.1", ... |