You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
logger.Info("This will be sent to sentry as a Log entry")
56
+
logger.Error("An error occurred", "user", "test-user") // this will be sent as an Event
57
+
// These will be ignored
58
+
logger.Debug("This will be ignored")
56
59
}
57
60
```
58
61
59
62
## Configuration
60
63
61
64
The slog-sentry package offers several options to customize how logs are handled and sent to Sentry. These are specified through the Option struct:
62
65
63
-
-`Level`: Minimum log level to send to Sentry. Defaults to `slog.LevelDebug`.
66
+
-`EventLevel`: Slice of specific levels to send `Events` to Sentry. Defaults to `[]slog.Level{slog.LevelError, LevelFatal}`.
67
+
68
+
-`LogLevel`: Slice of specific levels to send `Log` entries to Sentry. Defaults to `[]slog.Level{slog.LevelDebug, slog.LevelInfo, slog.LevelWarn, slog.LevelError, LevelFatal}`.
64
69
65
70
-`Hub`: Custom Sentry hub to use; defaults to the current Sentry hub if not set.
66
71
@@ -77,7 +82,7 @@ The slog-sentry package offers several options to customize how logs are handled
77
82
78
83
```go
79
84
handler:= slogSentry.Option{
80
-
Level: slog.LevelWarn,
85
+
EventLevel: slog.LevelWarn,
81
86
Converter: func(addSource bool, replaceAttr func([]string, slog.Attr) slog.Attr, attrs []slog.Attr, groups []string, record *slog.Record, hub *sentry.Hub) *sentry.Event {
82
87
// Custom conversion logic
83
88
return &sentry.Event{
@@ -88,6 +93,22 @@ handler := slogSentry.Option{
88
93
}.NewSentryHandler()
89
94
```
90
95
96
+
### Backwards Compatibility
97
+
98
+
The old `Level` field is Deprecated but still works and will be converted to a slice of all levels starting from the minimum level:
99
+
100
+
```go
101
+
// Old way (still works)
102
+
handler:= sentryslog.Option{
103
+
Level: slog.LevelWarn, // Will be converted to EventLevel: [Warn, Error, Fatal]
0 commit comments