Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Logger interface {
Panic(msg string, fields ...Fields)
WithFields(fields Fields) Logger
IsTraceEnabled() bool
IsDebugEnabled() bool
}

type Fields map[string]any
Expand All @@ -31,6 +32,10 @@ func (l *NoopLogger) IsTraceEnabled() bool {
return false
}

func (l *NoopLogger) IsDebugEnabled() bool {
return false
}

const ModuleField = "module"

func NewNoopLogger() *NoopLogger {
Expand Down
16 changes: 9 additions & 7 deletions pkg/wal/listener/kafka/wal_kafka_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ func (r *Reader) Listen(ctx context.Context) error {
return fmt.Errorf("reading from kafka: %w", err)
}

r.logger.Trace("received", loglib.Fields{
"topic": msg.Topic,
"partition": msg.Partition,
"offset": msg.Offset,
"key": msg.Key,
"wal_data": msg.Value,
})
if r.logger.IsTraceEnabled() {
r.logger.Trace("received", loglib.Fields{
"topic": msg.Topic,
"partition": msg.Partition,
"offset": msg.Offset,
"key": msg.Key,
"wal_data": msg.Value,
})
}

offset := &kafka.Offset{
Topic: msg.Topic,
Expand Down
12 changes: 7 additions & 5 deletions pkg/wal/listener/postgres/wal_pg_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,13 @@ func (l *Listener) listen(ctx context.Context) error {
continue
}

l.logger.Trace("", loglib.Fields{
"wal_end": l.lsnParser.ToString(msg.LSN),
"server_time": msg.ServerTime,
"wal_data": msg.Data,
})
if l.logger.IsTraceEnabled() {
l.logger.Trace("", loglib.Fields{
"wal_end": l.lsnParser.ToString(msg.LSN),
"server_time": msg.ServerTime,
"wal_data": msg.Data,
})
}

if err := l.processWALEvent(ctx, msg); err != nil {
return err
Expand Down
4 changes: 3 additions & 1 deletion pkg/wal/processor/filter/wal_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ func (f *Filter) ProcessWALEvent(ctx context.Context, event *wal.Event) error {
default:
// data events
if f.skipEvent(event) {
f.logger.Trace("skipping event", loglib.Fields{"schema": event.Data.Schema, "table": event.Data.Table})
if f.logger.IsTraceEnabled() {
f.logger.Trace("skipping event", loglib.Fields{"schema": event.Data.Schema, "table": event.Data.Table})
}
return nil
}
}
Expand Down
24 changes: 14 additions & 10 deletions pkg/wal/processor/injector/wal_injector.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,13 @@ func (in *Injector) injectColumnIDs(event *wal.Data, tbl *wal.DDLObject) error {
for i, col := range event.Columns {
schemaCol, found := tbl.GetColumnByName(col.Name)
if !found {
in.logger.Debug("column not found in table object", loglib.Fields{
"column": col.Name,
"table": tbl.Identity,
"object": tbl,
})
if in.logger.IsDebugEnabled() {
in.logger.Debug("column not found in table object", loglib.Fields{
"column": col.Name,
"table": tbl.Identity,
"object": tbl,
})
}
err = errors.Join(err, fmt.Errorf("failed to find column %q in table %s: %w", col.Name, tbl.Identity, processor.ErrColumnNotFound))
continue
}
Expand All @@ -234,11 +236,13 @@ func (in *Injector) injectColumnIDs(event *wal.Data, tbl *wal.DDLObject) error {
for i, col := range event.Identity { // should only be filled if event.Type is "D" or "U"
schemaCol, found := tbl.GetColumnByName(col.Name)
if !found {
in.logger.Debug("column not found in table object", loglib.Fields{
"column": col.Name,
"table": tbl.Identity,
"object": tbl,
})
if in.logger.IsDebugEnabled() {
in.logger.Debug("column not found in table object", loglib.Fields{
"column": col.Name,
"table": tbl.Identity,
"object": tbl,
})
}
err = errors.Join(err, fmt.Errorf("failed to find column %q in table %s: %w", col.Name, tbl.Identity, processor.ErrColumnNotFound))
continue
}
Expand Down
10 changes: 6 additions & 4 deletions pkg/wal/processor/search/search_batch_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,12 @@ func (i *BatchIndexer) ProcessWALEvent(ctx context.Context, event *wal.Event) (e
}
}()

i.logger.Trace("search batch indexer: received wal event", loglib.Fields{
"wal_data": event.Data,
"wal_commit_position": event.CommitPosition,
})
if i.logger.IsTraceEnabled() {
i.logger.Trace("search batch indexer: received wal event", loglib.Fields{
"wal_data": event.Data,
"wal_commit_position": event.CommitPosition,
})
}

msg, err := i.adapter.walEventToMsg(event)
if err != nil {
Expand Down
Loading