sendLine sends the line(s) to Lines channel, splitting longer lines if necessary. Return false if rate limit is reached.
(line string)
| 406 | // sendLine sends the line(s) to Lines channel, splitting longer lines |
| 407 | // if necessary. Return false if rate limit is reached. |
| 408 | func (tail *Tail) sendLine(line string) bool { |
| 409 | now := time.Now() |
| 410 | lines := []string{line} |
| 411 | |
| 412 | // Split longer lines |
| 413 | if tail.MaxLineSize > 0 && len(line) > tail.MaxLineSize { |
| 414 | lines = util.PartitionString(line, tail.MaxLineSize) |
| 415 | } |
| 416 | |
| 417 | for _, line := range lines { |
| 418 | tail.Lines <- &Line{line, now, nil} |
| 419 | } |
| 420 | |
| 421 | if tail.Config.RateLimiter != nil { |
| 422 | ok := tail.Config.RateLimiter.Pour(uint16(len(lines))) |
| 423 | if !ok { |
| 424 | tail.Logger.Printf("Leaky bucket full (%v); entering 1s cooloff period.\n", |
| 425 | tail.Filename) |
| 426 | return false |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | return true |
| 431 | } |
| 432 | |
| 433 | // Cleanup removes inotify watches added by the tail package. This function is |
| 434 | // meant to be invoked from a process's exit handler. Linux kernel may not |
no test coverage detected