From 8d489825d74fb24260f79f2f001199b0b6e33294 Mon Sep 17 00:00:00 2001 From: MrMelon54 Date: Sat, 27 Jul 2024 23:09:38 +0100 Subject: [PATCH] Add debug logging mode --- cmd/lavender/serve.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cmd/lavender/serve.go b/cmd/lavender/serve.go index 2037806..2429d0f 100644 --- a/cmd/lavender/serve.go +++ b/cmd/lavender/serve.go @@ -10,6 +10,7 @@ import ( "github.com/1f349/lavender/server" "github.com/1f349/mjwt" "github.com/1f349/violet/utils" + "github.com/charmbracelet/log" "github.com/golang-jwt/jwt/v4" "github.com/google/subcommands" _ "github.com/mattn/go-sqlite3" @@ -19,7 +20,10 @@ import ( "path/filepath" ) -type serveCmd struct{ configPath string } +type serveCmd struct { + configPath string + debugMode bool +} func (s *serveCmd) Name() string { return "serve" } @@ -27,6 +31,7 @@ func (s *serveCmd) Synopsis() string { return "Serve API authentication service" func (s *serveCmd) SetFlags(f *flag.FlagSet) { f.StringVar(&s.configPath, "conf", "", "/path/to/config.json : path to the config file") + f.BoolVar(&s.debugMode, "debug", false, "enable debug mode") } func (s *serveCmd) Usage() string { @@ -38,6 +43,10 @@ func (s *serveCmd) Usage() string { func (s *serveCmd) Execute(_ context.Context, _ *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus { logger.Logger.Info("Starting...") + if s.debugMode { + logger.Logger.SetLevel(log.DebugLevel) + } + if s.configPath == "" { logger.Logger.Fatal("Config flag is missing") return subcommands.ExitUsageError