Open Code-Hex opened 7 years ago
I think you should not trim newline from the line when write to file. https://github.com/Code-Hex/tail/blob/5ad6447941c464f021ac1c2475ddb04a6e2caf47/tail.go#L221
Because, We can think about these cases.
This code compare with tail -f
.
for line := range t.Lines {
fmt.Println(line.Text)
}
I am going to write a some messages.
% printf "hello\n" >> a.txt
% printf wor >> a.txt
% printf "ld\n" >> a.txt
Result,
# tail -f
hello
world(Displayed `ld` after once time displayed `wor`)
# hpcloud/tail
hello
world(It is displayed `world` at once)
# Code-Hex/tail
hello
wor(newlined)
ld
So, If you deleted code to trim the newline, We can get the correct result like follow this.
for line := range t.Lines {
fmt.Print(line.Text)
}
Then,
# tail -f
hello
world(Displayed `ld` after once time displayed `wor`)
# After remove code to trim newline from the line.
hello
world(Displayed `ld` after once time displayed `wor`)
What was the problem?
Even though enable the Follow mode, Could not get the last line if it is not newline on end of the line.
For example, I had read the file that is not followed by a newline on the last line using
github.com/hpcloud/tail
. file is like this.But, when I use
tail -f
, I could get the the last line. We must need to fix this problem.Thank you.