Skip to content

Commit

Permalink
Add Leo position vested and divested database records, Sentry log typ…
Browse files Browse the repository at this point in the history
…e check
  • Loading branch information
af-afk committed Sep 3, 2024
1 parent 94bf86e commit 46454a7
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions lib/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
package setup

import (
"context"
"fmt"
"log"
"log/slog"
"os"
"context"
"runtime/debug"
"strings"
"time"
Expand All @@ -26,7 +26,8 @@ const (
)

type Multihandler struct {
sentry, json slog.Handler
furthestSentry slog.Level // Furthest to go with Sentry.
sentry, json slog.Handler
}

func (h Multihandler) Enabled(ctx context.Context, record slog.Level) bool {
Expand All @@ -40,7 +41,7 @@ func (h Multihandler) WithAttrs(attrs []slog.Attr) slog.Handler {
}
return Multihandler{
sentry: s,
json: h.json.WithAttrs(attrs),
json: h.json.WithAttrs(attrs),
}
}
func (h Multihandler) WithGroup(name string) slog.Handler {
Expand All @@ -50,11 +51,16 @@ func (h Multihandler) WithGroup(name string) slog.Handler {
}
return Multihandler{
sentry: s,
json: h.json.WithGroup(name),
json: h.json.WithGroup(name),
}
}
func (h Multihandler) Handle(ctx context.Context, record slog.Record) error {
if s := h.sentry; s != nil {
// Hack here to make sure we don't log any inappropriate Sentry
// errors.
if record.Level < h.furthestSentry {
return nil
}
if err := s.Handle(ctx, record); err != nil {
return err
}
Expand All @@ -81,9 +87,11 @@ func init() {
}
var multihandler Multihandler
if dsn != "" { // DSN being set means we're using Sentry.
furthestSentry := slog.LevelError
multihandler.furthestSentry = furthestSentry
// We want to only track errors with Sentry.
multihandler.sentry = slogsentry.Option{
Level: slog.LevelError,
Level: furthestSentry,
}.
NewSentryHandler()
}
Expand Down

0 comments on commit 46454a7

Please sign in to comment.