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

10
main.go
View File

@@ -1,10 +1,10 @@
package main package main
import ( import (
"bytes"
"flag" "flag"
"os" "os"
"os/signal" "os/signal"
"regexp"
"strings" "strings"
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
@@ -23,8 +23,9 @@ var (
modalHandlers = map[string]func(s *discordgo.Session, i *discordgo.InteractionCreate){ modalHandlers = map[string]func(s *discordgo.Session, i *discordgo.InteractionCreate){
"register": RegisterModalHandler, "register": RegisterModalHandler,
} }
db *redis.Client db *redis.Client
debugFlag = flag.Bool("debug", false, "Enable debug logging") debugFlag = flag.Bool("debug", false, "Enable debug logging")
levelPattern = regexp.MustCompile(`level=(error|fatal|panic|warning)`)
) )
func init() { func init() {
@@ -152,7 +153,8 @@ func Bot() {
type OutputSplitter struct{} type OutputSplitter struct{}
func (splitter *OutputSplitter) Write(p []byte) (n int, err error) { 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.Stderr.Write(p)
} }
return os.Stdout.Write(p) return os.Stdout.Write(p)