35 lines
700 B
Go
35 lines
700 B
Go
package zlog
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
|
|
"gitlab.bareksa.com/backend/zen/core/zoptions"
|
|
)
|
|
|
|
type Notifier interface {
|
|
// Notify sends a notification from this Log Entry.
|
|
Notify(options ...zoptions.NotifyOption)
|
|
}
|
|
|
|
type NotificationHandler interface {
|
|
NotifyLog(ctx context.Context, record slog.Record, options ...zoptions.NotifyOption)
|
|
}
|
|
|
|
type notifier struct {
|
|
ctx context.Context
|
|
notifier NotificationHandler
|
|
record slog.Record
|
|
}
|
|
|
|
func (no notifier) Notify(options ...zoptions.NotifyOption) {
|
|
if no.notifier == nil {
|
|
return
|
|
}
|
|
no.notifier.NotifyLog(no.ctx, no.record, options...)
|
|
}
|
|
|
|
type nullNotifier struct{}
|
|
|
|
func (nullNotifier) Notify(options ...zoptions.NotifyOption) {}
|