-
Notifications
You must be signed in to change notification settings - Fork 501
Support lines of length more than 4096 bytes #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -170,8 +170,17 @@ func (tail *Tail) reopen() error { | |
| } | ||
|
|
||
| func (tail *Tail) readLine() ([]byte, error) { | ||
| line, _, err := tail.reader.ReadLine() | ||
| return line, err | ||
| line, isPrefix, err := tail.reader.ReadLine() | ||
| if !isPrefix || tail.MaxLineSize > 0 { | ||
| return line, err | ||
| } | ||
|
|
||
| buf := append([]byte(nil), line...) | ||
| for isPrefix && err == nil { | ||
| line, isPrefix, err = tail.reader.ReadLine() | ||
| buf = append(buf, line...) | ||
| } | ||
| return buf, err | ||
| } | ||
|
|
||
| func (tail *Tail) tailFileSync() { | ||
|
|
@@ -199,7 +208,7 @@ func (tail *Tail) tailFileSync() { | |
| } | ||
| } | ||
|
|
||
| tail.reader = bufio.NewReader(tail.file) | ||
| tail.reader = tail.newReader() | ||
|
|
||
| // Read line by line. | ||
| for { | ||
|
|
@@ -280,7 +289,7 @@ func (tail *Tail) waitForChanges() error { | |
| return err | ||
| } | ||
| tail.Logger.Printf("Successfully reopened %s", tail.Filename) | ||
| tail.reader = bufio.NewReader(tail.file) | ||
| tail.reader = tail.newReader() | ||
| return nil | ||
| } else { | ||
| tail.Logger.Printf("Stopping tail as file no longer exists: %s", tail.Filename) | ||
|
|
@@ -293,14 +302,22 @@ func (tail *Tail) waitForChanges() error { | |
| return err | ||
| } | ||
| tail.Logger.Printf("Successfully reopened truncated %s", tail.Filename) | ||
| tail.reader = bufio.NewReader(tail.file) | ||
| tail.reader = tail.newReader() | ||
| return nil | ||
| case <-tail.Dying(): | ||
| return ErrStop | ||
| } | ||
| panic("unreachable") | ||
| } | ||
|
|
||
| func (tail *Tail) newReader() *bufio.Reader { | ||
| if tail.MaxLineSize > 0 { | ||
| return bufio.NewReaderSize(tail.file, tail.MaxLineSize+2) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because it contains the buffer newlines code, add 2 bytes of CR/LF. |
||
| } else { | ||
| return bufio.NewReader(tail.file) | ||
| } | ||
| } | ||
|
|
||
| // sendLine sends the line(s) to Lines channel, splitting longer lines | ||
| // if necessary. Return false if rate limit is reached. | ||
| func (tail *Tail) sendLine(line []byte) bool { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it may be best to make
readLinereturn a slice of lines by splitting read lines perConfig.MaxLineSize, as otherwise there is no limit on how muchbufcan grow.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@masahide sorry - it looks like i overlooked something. two months ago, i noted above that the
bufvariable can grow unbounded, as theforloop doesn't split it per theMaxLineSizesetting and return a slice of lines. did you make any code changes for this? i don't see it in the current diff.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please try View full changes.
forloop is not performed if MaxLineSize is greater than or equal to zero.Does this have a problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that "the diff display" is wrong by "git push -f."