我如何结合这两个 golang 脚本来跟踪 UTF16LEBOM 的活动日志?
我正在为游戏(Eve Online)开发日志解析器。游戏中的聊天记录可以保存,我想用GoLang读取运行日志,并在“准备去死渣男!”中标记关键字“去死”。
我发现了两个单独工作的例子。将它们结合起来是一个我一直无法弄清楚的挑战。这里的第一个尾巴等效项: 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
慕无忌1623718
相关分类