zen/core/zlog/notification.go

35 lines
700 B
Go
Raw Normal View History

2024-08-27 15:22:42 +07:00
package zlog
import (
"context"
"log/slog"
"gitlab.bareksa.com/backend/zen/core/zoptions"
)
type Notifier interface {
// Notify sends a notification from this Log Entry.
2024-08-27 15:22:42 +07:00
Notify(options ...zoptions.NotifyOption)
}
type NotificationHandler interface {
NotifyLog(ctx context.Context, record slog.Record, options ...zoptions.NotifyOption)
2024-08-27 15:22:42 +07:00
}
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) {}