Use regex to filter which levels can match

This commit is contained in:
2024-03-09 17:52:53 -06:00
parent a72de046e1
commit 800bc54fbf

View File

@@ -1,10 +1,10 @@
package main
import (
"bytes"
"flag"
"os"
"os/signal"
"regexp"
"strings"
"github.com/bwmarrin/discordgo"
@@ -25,6 +25,7 @@ var (
}
db *redis.Client
debugFlag = flag.Bool("debug", false, "Enable debug logging")
levelPattern = regexp.MustCompile(`level=(error|fatal|panic|warning)`)
)
func init() {
@@ -152,7 +153,8 @@ func Bot() {
type OutputSplitter struct{}
func (splitter *OutputSplitter) Write(p []byte) (n int, err error) {
if bytes.Contains(p, []byte("level=error")) {
// Levels matched are contained within the OR'd group (error|fatal|panic|warning)
if levelPattern.Match(p) {
return os.Stderr.Write(p)
}
return os.Stdout.Write(p)