Skip to content

Commit 941a77d

Browse files
committed
binlogsyncer: Format config in logs
1 parent c855c26 commit 941a77d

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

replication/binlogsyncer.go

+11-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"crypto/tls"
66
"encoding/binary"
7+
"encoding/json"
78
"fmt"
89
"net"
910
"os"
@@ -109,13 +110,13 @@ type BinlogSyncerConfig struct {
109110

110111
//Option function is used to set outside of BinlogSyncerConfig, between mysql connection and COM_REGISTER_SLAVE
111112
//For MariaDB: slave_gtid_ignore_duplicates、skip_replication、slave_until_gtid
112-
Option func(*client.Conn) error
113+
Option func(*client.Conn) error `json:"-"`
113114

114115
// Set Logger
115116
Logger *log.Logger
116117

117118
// Set Dialer
118-
Dialer client.Dialer
119+
Dialer client.Dialer `json:"-"`
119120
}
120121

121122
// BinlogSyncer syncs binlog event from server.
@@ -160,8 +161,14 @@ func NewBinlogSyncer(cfg BinlogSyncerConfig) *BinlogSyncer {
160161

161162
// Clear the Password to avoid outputing it in log.
162163
pass := cfg.Password
163-
cfg.Password = ""
164-
cfg.Logger.Infof("create BinlogSyncer with config %v", cfg)
164+
cfg.Password = "<hidden>"
165+
jsonCfg, err := json.Marshal(cfg)
166+
if err != nil {
167+
cfg.Logger.Warnf("Failed to encode config as JSON: %s", err)
168+
cfg.Logger.Infof("create BinlogSyncer with config %#v", cfg)
169+
}
170+
cfg.Logger.Infof("create BinlogSyncer with config %s", jsonCfg)
171+
165172
cfg.Password = pass
166173

167174
b := new(BinlogSyncer)

0 commit comments

Comments
 (0)