Skip to content

Commit

Permalink
Change log level based on env variable, also add response and status …
Browse files Browse the repository at this point in the history
…code to subscription creating logging
  • Loading branch information
bsquidwrd committed May 3, 2024
1 parent ba3fcc3 commit 7bbf796
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
10 changes: 8 additions & 2 deletions cmd/discord_notifier/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,19 @@ import (
const queueName = "discord_notifier"

func main() {
debugEnabled := os.Getenv("DEBUG")
logLevel := slog.LevelInfo

if debugEnabled != "" {
logLevel = slog.LevelDebug
}
loggerOptions := &slog.HandlerOptions{
Level: slog.LevelDebug,
Level: logLevel,
}
logger := slog.New(slog.NewJSONHandler(os.Stdout, loggerOptions))
slog.SetDefault(logger)

slog.Info("Discord Notifier Starting Up...")
slog.Info("Discord Notifier Starting Up...", "log_level", logLevel)

port := os.Getenv("PORT")
if port == "" {
Expand Down
10 changes: 8 additions & 2 deletions cmd/receiver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@ import (
)

func main() {
debugEnabled := os.Getenv("DEBUG")
logLevel := slog.LevelInfo

if debugEnabled != "" {
logLevel = slog.LevelDebug
}
loggerOptions := &slog.HandlerOptions{
Level: slog.LevelDebug,
Level: logLevel,
}
logger := slog.New(slog.NewJSONHandler(os.Stdout, loggerOptions))
slog.SetDefault(logger)

slog.Info("Receiver Starting Up...")
slog.Info("Receiver Starting Up...", "log_level", logLevel)

port := os.Getenv("PORT")
if port == "" {
Expand Down
4 changes: 2 additions & 2 deletions internal/receiver_handlers/authorization_grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ func processAuthorizationGrant(dbServices *database.ReceiverService, notificatio
slog.Debug("Set subType")
go func() {
slog.Debug("Inside GO function to create subscription")
_, response, err := twitch.CallApi(dbServices, http.MethodPost, "eventsub/subscriptions", body, nil)
statusCode, response, err := twitch.CallApi(dbServices, http.MethodPost, "eventsub/subscriptions", body, nil)
if err != nil {
slog.Warn("Could not subscribe to event for user", "subscription_type", subType, "error", err, "response", string(response))
} else {
slog.Debug("Successfully requested creation of event")
slog.Debug("Successfully requested creation of event", "response", string(response), slog.Int("status_code", statusCode))
}
}()
}
Expand Down

0 comments on commit 7bbf796

Please sign in to comment.