From 2a5fe0ceef7adb4a2bd35923d704763585a456d1 Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Thu, 6 May 2021 07:36:52 -0400 Subject: [PATCH] Add debug level command --- commands.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/commands.go b/commands.go index ac17cc1..2597a5c 100644 --- a/commands.go +++ b/commands.go @@ -8,6 +8,8 @@ import ( "strconv" "strings" "time" + + "github.com/rudi9719/loggy" ) func setupCommands() { @@ -69,6 +71,15 @@ func setupCommands() { Exec: Commands, } commands = append(commands, listCommands) + + debugLevel := Command{ + Name: "Debug Level", + RequiresAdmin: true, + Keywords: []string{"debug"}, + Exec: Debug, + Help: "Set the log level for loggy", + } + commands = append(commands, debugLevel) } func Commands(b BotCommand) bool { @@ -87,6 +98,17 @@ func Commands(b BotCommand) bool { return true } +func Debug(b BotCommand) bool { + defer log.PanicSafe() + level, err := strconv.Atoi(b.Parts[0]) + if err != nil { + return false + } + config.LogOpts.Level = loggy.LogLevel(level) + log = loggy.NewLogger(config.LogOpts) + return true +} + func Reboot(b BotCommand) bool { defer log.PanicSafe() if strings.Contains(b.Message.Content, rebootToken) {