Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewMiddleware ¶
func NewMiddleware(options *HandlerOptions) func(slog.Handler) slog.Handler
NewMiddleware creates a slogbugsnag.Handler slog.Handler middleware that conforms to github.com/samber/slog-multi.Middleware interface. It can be used with slogmulti methods such as Pipe to easily setup a pipeline of slog handlers:
slog.SetDefault(slog.New(slogmulti. Pipe(slogcontext.NewMiddleware(&slogcontext.HandlerOptions{})). Pipe(slogdedup.NewOverwriteMiddleware(&slogdedup.OverwriteHandlerOptions{})). Pipe(slogbugsnag.NewMiddleware(&slogbugsnag.HandlerOptions{})). Handler(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{})), ))
Types ¶
type Email ¶
type Email string
Email is a string that, if used as a log attribute value, will be filled in on the bugsnag.User struct.
func (Email) BugsnagUserEmail ¶
BugsnagUserEmail returns the bugsnag user email
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is a slog.Handler middleware that will automatically send log lines to Bugsnag (https://www.bugsnag.com/) if they are at least a certain level (Error by default). The latest error in the log line is sent as the primary error, and all log attributes and the context are put into metadata and user tabs and sent with the bug. It passes the final record and attributes off to the next handler when finished. The Bugsnag V2 library should be configured before any logging is done.
bugsnag.Configure(bugsnag.Configuration{APIKey: ...})
func NewHandler ¶
func NewHandler(next slog.Handler, opts *HandlerOptions) *Handler
NewHandler creates a slog.Handler middleware that will automatically send log lines to Bugsnag (https://www.bugsnag.com/) if they are at least a certain level (Error by default). The latest error in the log line is sent as the primary error, and all log attributes and the context are put into metadata and user tabs and sent with the bug. It passes the final record and attributes off to the next handler when finished. The Bugsnag V2 library should be configured before any logging is done.
bugsnag.Configure(bugsnag.Configuration{APIKey: ...})
If opts is nil, the default options are used.
func (*Handler) Close ¶
func (h *Handler) Close()
Close stops the handler from sending any new bugs after this point to bugsnag, but it will continue to pass the log records to the next handler. This call will block until all bugs currently queued have been sent.
func (*Handler) Enabled ¶
Enabled reports whether the next handler handles records at the given level. The handler ignores records whose level is lower.
func (*Handler) Handle ¶
Handle collects all attributes and groups, then passes the record and its attributes to the next handler.
type HandlerOptions ¶
type HandlerOptions struct { // Level reports the minimum record level that will be sent to bugsnag. // The handler ignores but still passes along records with lower levels // to the next handler. // If NotifyLevel is nil, the handler assumes LevelError. // The handler calls NotifyLevel.Level() for each record processed; // to adjust the minimum level dynamically, use a LevelVar. NotifyLevel slog.Leveler // UnhandledLevel reports the minimum record level that will be sent to // bugsnag as an unhandled error. // If UnhandledLevel is nil, the handler assumes slog.LevelError + 4. UnhandledLevel slog.Leveler // Notifiers is a worker pool, where each worker synchronously sends // bugs to bugsnag. This gives us the ability to flush all bugs before // terminating an application, by calling Close on the pool or the handler. // If nil, a default notifier worker pool will be started. Notifiers *NotifierWorkers }
HandlerOptions are options for a Handler
type ID ¶
type ID string
ID is a string that, if used as a log attribute value, will be filled in on the bugsnag.User struct. The ID is also used to determine the number of users affected by the bug, in bugsnag's system.
func (ID) BugsnagUserID ¶
BugsnagUserID returns the bugsnag user id
type Name ¶
type Name string
Name is a string that, if used as a log attribute value, will be filled in on the bugsnag.User struct.
func (Name) BugsnagUserName ¶
BugsnagUserName returns the bugsnag user name
type NotifierOptions ¶ added in v0.2.0
type NotifierOptions struct { // Notifier is the bugsnag notifier that will be used. It should be // configured, and may contain custom rawData added to all events. // If nil, a default one will be created. Notifier *bugsnag.Notifier // MaxNotifierConcurrency sets the maximum number of bugs that can be sent // to bugsnag in parallel. It defaults to the number of CPU's. // Bugs are placed on a buffered channel to be sent to bugsnag, in order // to not block or delay the log call from returning. The bugs are then // sent to bugsnag synchronously by a number of workers equal to this int. MaxNotifierConcurrency int }
NotifierOptions are options for NotifierWorkers
type NotifierWorkers ¶ added in v0.2.0
type NotifierWorkers struct {
// contains filtered or unexported fields
}
NotifierWorkers can run a worker pool, where each worker synchronously sends bugs to bugsnag. This gives us the ability to flush all bugs before terminating an application, by calling NotifierWorkers.Close
func NewNotifierWorkers ¶ added in v0.2.0
func NewNotifierWorkers(opts *NotifierOptions) *NotifierWorkers
NewNotifierWorkers creates and starts a worker pool, where each worker synchronously sends bugs to bugsnag. This gives us the ability to flush all bugs before terminating an application, by calling NotifierWorkers.Close
func (*NotifierWorkers) Close ¶ added in v0.2.0
func (nw *NotifierWorkers) Close()
Close stops the NotifierWorkers from accepting any new bugs to its queue. This call will block until all bugs currently queued have been sent.