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