-
Notifications
You must be signed in to change notification settings - Fork 0
/
logreader.go
79 lines (64 loc) · 1.38 KB
/
logreader.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"bufio"
"fmt"
"log"
"os"
"strings"
"time"
)
func tickTime() {
for {
tick <- true
time.Sleep(100 * time.Millisecond)
}
}
func readLog() {
// Start log reading ticker
go tickTime()
readlog := false
// Reads log every tick.
for {
<-tick
// Reads log line by line
logFile := readLogFile()
scanLog := bufio.NewScanner(strings.NewReader(logFile))
var logLinesTmp []string
// Appends each log line to a variable.
for scanLog.Scan() {
logLinesTmp = append(logLinesTmp, scanLog.Text())
}
// Only takes action on log lines that are new, and ignores old ones.
for y, x := range logLinesTmp {
if y > (len(logLines) - 1) {
if readlog {
// Handles new log lines.
logHandler(x)
}
}
}
logLines = logLinesTmp
// Set to true after the first for loop passes
readlog = true
}
}
// Runs the appropriate function depending on the log line contents.
func logHandler(newline string) bool {
if strings.Contains(newline, "FlightLogger:") && strings.Contains(newline, "has spawned.") {
fmt.Println("Splash 1, bearing 0")
bwa()
}
return false
}
// reads the log file.
func readLogFile() string {
home, err := os.UserHomeDir()
if err != nil {
log.Panic(err)
}
file, err := os.ReadFile(home + "\\AppData\\LocalLow\\Boundless Dynamics, LLC\\VTOLVR\\Player.log")
if err != nil {
log.Panic(err)
}
return string(file)
}