From 470866ba05d268f29dbf15ef6c25ffe19170d4a4 Mon Sep 17 00:00:00 2001 From: Mayank Thakur Date: Tue, 31 Oct 2023 18:27:40 +0530 Subject: [PATCH] feat: added debug flag in the SuperTokenConfig in the init() for logging --- supertokens/logger.go | 1 - supertokens/models.go | 1 + supertokens/supertokens.go | 10 ++++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/supertokens/logger.go b/supertokens/logger.go index 7dbcdd1e..210d490a 100644 --- a/supertokens/logger.go +++ b/supertokens/logger.go @@ -28,6 +28,5 @@ func LogDebugMessage(message string) { _, exists := os.LookupEnv("SUPERTOKENS_DEBUG") if exists { logger.Printf(formatMessage(message)) - } } diff --git a/supertokens/models.go b/supertokens/models.go index 4a625735..92172620 100644 --- a/supertokens/models.go +++ b/supertokens/models.go @@ -46,6 +46,7 @@ type TypeInput struct { AppInfo AppInfo RecipeList []Recipe Telemetry *bool + Debug *bool OnSuperTokensAPIError func(err error, req *http.Request, res http.ResponseWriter) } diff --git a/supertokens/supertokens.go b/supertokens/supertokens.go index d1e7b017..0789bf84 100644 --- a/supertokens/supertokens.go +++ b/supertokens/supertokens.go @@ -20,6 +20,7 @@ import ( "errors" "flag" "net/http" + "os" "reflect" "strconv" "strings" @@ -35,6 +36,7 @@ type superTokens struct { RecipeModules []RecipeModule OnSuperTokensAPIError func(err error, req *http.Request, res http.ResponseWriter) Telemetry *bool + Debug *bool } // this will be set to true if this is used in a test app environment @@ -54,6 +56,14 @@ func supertokensInit(config TypeInput) error { superTokens.OnSuperTokensAPIError = config.OnSuperTokensAPIError } + superTokens.Debug = config.Debug + if superTokens.Debug != nil && *superTokens.Debug { + err := os.Setenv("SUPERTOKENS_DEBUG", "1") + if err != nil { + return err + } + } + LogDebugMessage("Started SuperTokens with debug logging (supertokens.Init called)") appInfoJsonString, _ := json.Marshal(config.AppInfo)