Skip to content

Commit df5bf1d

Browse files
committed
binlogsyncer: Format config in logs
1 parent c4a17aa commit df5bf1d

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

replication/binlogsyncer.go

+12-5
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"
@@ -111,15 +112,15 @@ type BinlogSyncerConfig struct {
111112

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

116117
// Set Logger
117118
Logger loggers.Advanced
118119

119120
// Set Dialer
120-
Dialer client.Dialer
121+
Dialer client.Dialer `json:"-"`
121122

122-
RowsEventDecodeFunc func(*RowsEvent, []byte) error
123+
RowsEventDecodeFunc func(*RowsEvent, []byte) error `json:"-"`
123124

124125
DiscardGTIDSet bool
125126
}
@@ -169,8 +170,14 @@ func NewBinlogSyncer(cfg BinlogSyncerConfig) *BinlogSyncer {
169170

170171
// Clear the Password to avoid outputing it in log.
171172
pass := cfg.Password
172-
cfg.Password = ""
173-
cfg.Logger.Infof("create BinlogSyncer with config %v", cfg)
173+
cfg.Password = "<hidden>"
174+
jsonCfg, err := json.Marshal(cfg)
175+
if err != nil {
176+
cfg.Logger.Warnf("Failed to encode config as JSON: %s", err)
177+
cfg.Logger.Infof("create BinlogSyncer with config %#v", cfg)
178+
}
179+
cfg.Logger.Infof("create BinlogSyncer with config %s", jsonCfg)
180+
174181
cfg.Password = pass
175182

176183
b := new(BinlogSyncer)

0 commit comments

Comments
 (0)