added regex and duplicate line filtering
This commit is contained in:
@ -8,6 +8,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
|
"regexp"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -21,7 +22,6 @@ var (
|
|||||||
srv_cmd *exec.Cmd
|
srv_cmd *exec.Cmd
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
// reload settings (and maybe other things too)
|
// reload settings (and maybe other things too)
|
||||||
func reload() {
|
func reload() {
|
||||||
settings, _ = toml.LoadFile("serverwrapper.toml")
|
settings, _ = toml.LoadFile("serverwrapper.toml")
|
||||||
@ -38,9 +38,6 @@ func settings_list(option string) []string {
|
|||||||
|
|
||||||
//builds the cmd which is called to run the server
|
//builds the cmd which is called to run the server
|
||||||
func build_cmd() (string, []string) {
|
func build_cmd() (string, []string) {
|
||||||
//for debugging
|
|
||||||
//return "ping", []string{"8.8.8.8"}
|
|
||||||
|
|
||||||
java_args := []string{"-jar"}
|
java_args := []string{"-jar"}
|
||||||
|
|
||||||
jvm_args := settings_list("server.jvm-args")
|
jvm_args := settings_list("server.jvm-args")
|
||||||
@ -93,6 +90,11 @@ func server_run(g *gocui.Gui) {
|
|||||||
log.Panicln("Failed to call server command \"" + srv_cmd.String() + "\"")
|
log.Panicln("Failed to call server command \"" + srv_cmd.String() + "\"")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//preload the regexes from the config
|
||||||
|
regexes := settings_list("logging.stdout_excludes")
|
||||||
|
|
||||||
|
lastline := ""
|
||||||
|
|
||||||
//read pipes and write them to the ring buffer
|
//read pipes and write them to the ring buffer
|
||||||
buf := bufio.NewScanner(stdout)
|
buf := bufio.NewScanner(stdout)
|
||||||
for {
|
for {
|
||||||
@ -103,12 +105,31 @@ func server_run(g *gocui.Gui) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Fprintln(v, buf.Text())
|
|
||||||
|
line := buf.Text()
|
||||||
|
match := lastline == line
|
||||||
|
lastline = line
|
||||||
|
for i := range regexes {
|
||||||
|
match_line, err := regexp.Match(regexes[i], []byte(line))
|
||||||
|
if err != nil {
|
||||||
|
v2, _ := g.View("status")
|
||||||
|
fmt.Fprintln(v2, err)
|
||||||
|
}
|
||||||
|
match = match || match_line
|
||||||
|
if match {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !match {
|
||||||
|
fmt.Fprintln(v, buf.Text())
|
||||||
|
}
|
||||||
|
|
||||||
g.SetCurrentView("input")
|
g.SetCurrentView("input")
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
time.Sleep(10 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -157,6 +178,7 @@ func inputHandler(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) {
|
|||||||
case key == gocui.KeyEnter:
|
case key == gocui.KeyEnter:
|
||||||
s := v.Buffer()
|
s := v.Buffer()
|
||||||
srv_stdin.Write([]byte(s))
|
srv_stdin.Write([]byte(s))
|
||||||
|
srv_stdin.Write([]byte("\n"))
|
||||||
v.EditDeleteToStartOfLine()
|
v.EditDeleteToStartOfLine()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -210,7 +232,7 @@ func killserver(g *gocui.Gui, v *gocui.View) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
v_status.Clear()
|
v_status.Clear()
|
||||||
err = srv_cmd.Process.Signal(syscall.SIGTERM)
|
err = srv_cmd.Process.Signal(syscall.SIGINT)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(v_status, fmt.Sprint(err))
|
fmt.Fprintf(v_status, fmt.Sprint(err))
|
||||||
}
|
}
|
||||||
@ -228,7 +250,12 @@ func procstatus(g *gocui.Gui, v *gocui.View) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
v_status.Clear()
|
v_status.Clear()
|
||||||
fmt.Fprintf(v_status, fmt.Sprint(srv_cmd.ProcessState))
|
state := srv_cmd.ProcessState
|
||||||
|
if state == nil {
|
||||||
|
fmt.Fprintf(v_status, "Server Process is still running")
|
||||||
|
} else {
|
||||||
|
fmt.Fprintf(v_status, fmt.Sprint(state))
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -249,8 +276,8 @@ func quit(g *gocui.Gui, v *gocui.View) error {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
v_status.Clear()
|
v_status.Clear()
|
||||||
fmt.Fprintf(v_status, "Server process still running, sending SIGTERM... ")
|
fmt.Fprintf(v_status, "Server process still running, sending SIGINT... ")
|
||||||
srv_cmd.Process.Signal(syscall.SIGTERM)
|
srv_cmd.Process.Signal(syscall.SIGINT)
|
||||||
err = srv_cmd.Wait()
|
err = srv_cmd.Wait()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(v_status, fmt.Sprint(err))
|
fmt.Fprintf(v_status, fmt.Sprint(err))
|
||||||
|
|||||||
@ -37,8 +37,9 @@ jolokia = "/home/minecraft/ServerWrapper/jolokia-jvm-1.6.2-agent.jar"
|
|||||||
mccron-path = "/srv/mcrcon-0.7.1-linux-x86-64/./mcrcon"
|
mccron-path = "/srv/mcrcon-0.7.1-linux-x86-64/./mcrcon"
|
||||||
mccron-args = ["-p YiibUn8UzKBIQ52ZJu4P"]
|
mccron-args = ["-p YiibUn8UzKBIQ52ZJu4P"]
|
||||||
|
|
||||||
|
# note that toml already escapes \, so you need double escape it for regex
|
||||||
[logging]
|
[logging]
|
||||||
stdout_excludes = [
|
stdout_excludes = [
|
||||||
".*[RCON Client.*",
|
".*\\[RCON Client.*",
|
||||||
".*[RCON Listener.*"
|
".*\\[RCON Listener.*"
|
||||||
]
|
]
|
||||||
Reference in New Issue
Block a user