(l *userlog.UserLog, buf []byte)
| 55 | ) |
| 56 | |
| 57 | func (f *plainLogFile) Write(l *userlog.UserLog, buf []byte) (int, error) { |
| 58 | w := f.writer |
| 59 | if w == nil { |
| 60 | return 0, errLogClosed |
| 61 | } |
| 62 | if f.capacity <= 0 { |
| 63 | return 0, errOverCapacity |
| 64 | } |
| 65 | tmp := bytes.NewBuffer(nil) |
| 66 | i, j := 0, 0 |
| 67 | for i < len(buf) { |
| 68 | j = bytes.Index(buf[i:], LineByte) |
| 69 | if j < 0 { |
| 70 | j = len(buf) |
| 71 | } else if j > 0 { |
| 72 | j = i + j |
| 73 | } else { |
| 74 | i++ |
| 75 | continue |
| 76 | } |
| 77 | tmp.WriteString(l.Created.UTC().Format(time.RFC3339)) |
| 78 | tmp.WriteByte('\t') |
| 79 | tmp.Write(buf[i:j]) |
| 80 | tmp.WriteByte('\n') |
| 81 | i = j + 1 |
| 82 | } |
| 83 | w.Write(tmp.Bytes()) |
| 84 | atomic.AddInt32(&f.capacity, int32(-i)) |
| 85 | return i, nil |
| 86 | } |
| 87 | |
| 88 | func (f *plainLogFile) Close() error { |
| 89 | w := f.writer |
nothing calls this directly
no test coverage detected