Skip to content

Commit

Permalink
read log from file (#787)
Browse files Browse the repository at this point in the history
Co-authored-by: miaodanyang <miaodanyang@baidu.com>
  • Loading branch information
miaow999 and miaodanyang committed Oct 11, 2023
1 parent f04074d commit 823cc8d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions ami/native/native.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,14 @@ func getLogForWindows(logPath string, tailLines int64, pipe ami.Pipe) error {
cursor := int64(0)
cnt := int64(0)
// 逆向遍历字节,寻找倒数第n行数据
fileInfo, err := file.Stat()
if err != nil {
return errors.Trace(err)
}
size := fileInfo.Size()
for {
cursor -= 1
_, err = file.Seek(cursor, io.SeekEnd)
cursor += 1
_, err = file.Seek(size-cursor, io.SeekStart)
if err != nil {
_, err = file.Seek(0, 0)
if err != nil {
Expand Down

0 comments on commit 823cc8d

Please sign in to comment.