我如何结合这两个golang脚本来跟踪一个活动日志,即UTF16LEBOM?

我正在为一个游戏(Eve Online)开发日志解析器。在游戏聊天日志可以保存,我想用戈郎阅读运行日志和标志上的关键字“死”在“准备死渣滓!”

我发现了两个分别起作用的例子。将它们结合起来是一个我一直无法理解的挑战。这里的第一个尾等价:https://medium.com/@arunprabhu.1/tailing-a-file-in-golang-72944204f22b

二次读取文件,使其易读且没有多余字符:https://github.com/TomOnTime/utfutil/

我一直在尝试用“等效”替换utfutil中的代码,但它似乎缺少几个函数。

// EDIT Almost working. It doesn't look like utfutil is defering the close.

package main

import (
    "bufio"
    "fmt"
    "io"
    "time"
    
    "github.com/TomOnTime/utfutil"
)

func main() {
    logfilefile := "C:/Users/user/Documents/EVE/logs/Chatlogs/chat_20220709_022129_1006197774.txt"
    file, err := utfutil.OpenFile(logfilefile, utfutil.WINDOWS)
    if err != nil {
        return
    }

    defer file.Close()

    reader := bufio.NewReader(file)
    for {
        line, err := reader.ReadString('\n')
        if err != nil {
            if err == io.EOF {
                // without this sleep you would hogg the CPU
                time.Sleep(500 * time.Millisecond)
                continue
            }

            break
        }

        fmt.Printf(string(line))
    }
}
<cut white space>
        ---------------------------------------------------------------

          Channel ID:      local
          Channel Name:    Local
          Listener:        Steve
          Session started: 2022.07.07 16:18:21
        ---------------------------------------------------------------

[ 2022.07.07 17:11:44 ] Steve > hello world
[ 2022.07.07 17:11:48 ] John > hello world
[ 2022.07.07 17:11:51 ] James > hello world
[ 2022.07.07 19:36:53 ] Bob > hello world