From cd89c8691b26f044c59aeb2d5e9bd8abbfe42e6b Mon Sep 17 00:00:00 2001 From: Tony Holdstock-Brown Date: Tue, 8 Oct 2024 23:55:46 +0000 Subject: [PATCH] Add logger to logical decoding singleton --- pkg/decoder/pg_logical_v1.go | 7 +++++-- pkg/replicator/pgreplicator/pg.go | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/decoder/pg_logical_v1.go b/pkg/decoder/pg_logical_v1.go index e43ba3b..b978776 100644 --- a/pkg/decoder/pg_logical_v1.go +++ b/pkg/decoder/pg_logical_v1.go @@ -12,8 +12,9 @@ import ( "github.com/jackc/pgx/v5/pgtype" ) -func NewV1LogicalDecoder(s *schema.PGXSchemaLoader) Decoder { +func NewV1LogicalDecoder(s *schema.PGXSchemaLoader, log *slog.Logger) Decoder { return v1LogicalDecoder{ + log: log, schema: s, relations: make(map[uint32]*pglogrepl.RelationMessage), } @@ -81,7 +82,9 @@ func (v v1LogicalDecoder) Decode(in []byte, cs *changeset.Changeset) (bool, erro default: // Unsupported message - log and carry on. - v.log.Debug("unsupported message type in v1 decoder", "msg_type", msgType.String()) + if v.log != nil { + v.log.Debug("unsupported message type in v1 decoder", "msg_type", msgType) + } } return false, nil diff --git a/pkg/replicator/pgreplicator/pg.go b/pkg/replicator/pgreplicator/pg.go index 9152922..4735a27 100644 --- a/pkg/replicator/pgreplicator/pg.go +++ b/pkg/replicator/pgreplicator/pg.go @@ -100,7 +100,7 @@ func New(ctx context.Context, opts Opts) (PostgresReplicator, error) { opts: opts, conn: replConn, queryConn: pgxc, - decoder: decoder.NewV1LogicalDecoder(sl), + decoder: decoder.NewV1LogicalDecoder(sl, opts.Log), log: opts.Log, }, nil }