appview/notify: pass logger with mergedLogger #693

merged
opened by boltless.me targeting master from boltless.me/core: feat/search
Changed files
+14 -9
appview
indexer
notify
state
+3 -3
appview/indexer/notifier.go
···
var _ notify.Notifier = &Indexer{}
func (ix *Indexer) NewIssue(ctx context.Context, issue *models.Issue) {
-
l := log.FromContext(ctx).With("notifier", "indexer.NewIssue", "issue", issue)
+
l := log.FromContext(ctx).With("notifier", "indexer", "issue", issue)
l.Debug("indexing new issue")
err := ix.Issues.Index(ctx, *issue)
if err != nil {
···
}
func (ix *Indexer) NewIssueClosed(ctx context.Context, issue *models.Issue) {
-
l := log.FromContext(ctx).With("notifier", "indexer.NewIssueClosed", "issue", issue)
+
l := log.FromContext(ctx).With("notifier", "indexer", "issue", issue)
l.Debug("updating an issue")
err := ix.Issues.Index(ctx, *issue)
if err != nil {
···
}
func (ix *Indexer) DeleteIssue(ctx context.Context, issue *models.Issue) {
-
l := log.FromContext(ctx).With("notifier", "indexer.DeleteIssue", "issue", issue)
+
l := log.FromContext(ctx).With("notifier", "indexer", "issue", issue)
l.Debug("deleting an issue")
err := ix.Issues.Delete(ctx, issue.Id)
if err != nil {
+10 -5
appview/notify/merged_notifier.go
···
import (
"context"
+
"log/slog"
"reflect"
"sync"
"tangled.org/core/appview/models"
+
"tangled.org/core/log"
)
type mergedNotifier struct {
notifiers []Notifier
+
logger *slog.Logger
}
-
func NewMergedNotifier(notifiers ...Notifier) Notifier {
-
return &mergedNotifier{notifiers}
+
func NewMergedNotifier(notifiers []Notifier, logger *slog.Logger) Notifier {
+
return &mergedNotifier{notifiers, logger}
}
var _ Notifier = &mergedNotifier{}
// fanout calls the same method on all notifiers concurrently
-
func (m *mergedNotifier) fanout(method string, args ...any) {
+
func (m *mergedNotifier) fanout(method string, ctx context.Context, args ...any) {
+
ctx = log.IntoContext(ctx, m.logger.With("method", method))
var wg sync.WaitGroup
for _, n := range m.notifiers {
wg.Add(1)
go func(notifier Notifier) {
defer wg.Done()
v := reflect.ValueOf(notifier).MethodByName(method)
-
in := make([]reflect.Value, len(args))
+
in := make([]reflect.Value, len(args) + 1)
+
in[0] = reflect.ValueOf(ctx)
for i, arg := range args {
-
in[i] = reflect.ValueOf(arg)
+
in[i+1] = reflect.ValueOf(arg)
}
v.Call(in)
}(n)
+1 -1
appview/state/state.go
···
notifiers = append(notifiers, phnotify.NewPosthogNotifier(posthog))
}
notifiers = append(notifiers, indexer)
-
notifier := notify.NewMergedNotifier(notifiers...)
+
notifier := notify.NewMergedNotifier(notifiers, tlog.SubLogger(logger, "notify"))
state := &State{
d,