Skip to content

Commit d3577b5

Browse files
committed
Use the Stringer interface to output discovery id
1 parent b6925f1 commit d3577b5

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

client.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func (disc *Client) jsonDecodeLoop(in io.Reader, outChan chan<- *discoveryMessag
127127
disc.incomingMessagesError = err
128128
disc.statusMutex.Unlock()
129129
close(outChan)
130-
disc.logger.Errorf("stopped discovery %s decode loop: %v", disc.id, err)
130+
disc.logger.Errorf("stopped discovery %s decode loop: %v", disc, err)
131131
}
132132

133133
for {
@@ -143,7 +143,7 @@ func (disc *Client) jsonDecodeLoop(in io.Reader, outChan chan<- *discoveryMessag
143143
closeAndReportError(err)
144144
return
145145
}
146-
disc.logger.Infof("from discovery %s received message %s", disc.id, msg)
146+
disc.logger.Infof("from discovery %s received message %s", disc, msg)
147147
if msg.EventType == "add" {
148148
if msg.Port == nil {
149149
closeAndReportError(errors.New("invalid 'add' message: missing port"))
@@ -178,7 +178,7 @@ func (disc *Client) waitMessage(timeout time.Duration) (*discoveryMessage, error
178178
}
179179
return msg, nil
180180
case <-time.After(timeout):
181-
return nil, fmt.Errorf("timeout waiting for message from %s", disc.id)
181+
return nil, fmt.Errorf("timeout waiting for message from %s", disc)
182182
}
183183
}
184184

@@ -198,7 +198,7 @@ func (disc *Client) sendCommand(command string) error {
198198
}
199199

200200
func (disc *Client) runProcess() error {
201-
disc.logger.Infof("starting discovery %s process", disc.id)
201+
disc.logger.Infof("starting discovery %s process", disc)
202202
proc, err := paths.NewProcess(nil, disc.processArgs...)
203203
if err != nil {
204204
return err
@@ -224,12 +224,12 @@ func (disc *Client) runProcess() error {
224224
disc.statusMutex.Lock()
225225
defer disc.statusMutex.Unlock()
226226
disc.process = proc
227-
disc.logger.Infof("started discovery %s process", disc.id)
227+
disc.logger.Infof("started discovery %s process", disc)
228228
return nil
229229
}
230230

231231
func (disc *Client) killProcess() error {
232-
disc.logger.Infof("killing discovery %s process", disc.id)
232+
disc.logger.Infof("killing discovery %s process", disc)
233233
if disc.process != nil {
234234
if err := disc.process.Kill(); err != nil {
235235
return err
@@ -241,7 +241,7 @@ func (disc *Client) killProcess() error {
241241
disc.statusMutex.Lock()
242242
defer disc.statusMutex.Unlock()
243243
disc.stopSync()
244-
disc.logger.Infof("killed discovery %s process", disc.id)
244+
disc.logger.Infof("killed discovery %s process", disc)
245245
return nil
246246
}
247247

@@ -263,7 +263,7 @@ func (disc *Client) Run() (err error) {
263263
if err := disc.killProcess(); err != nil {
264264
// Log failure to kill the process, ideally that should never happen
265265
// but it's best to know it if it does
266-
disc.logger.Errorf("Killing discovery %s after unsuccessful start: %s", disc.id, err)
266+
disc.logger.Errorf("Killing discovery %s after unsuccessful start: %s", disc, err)
267267
}
268268
}()
269269

@@ -340,7 +340,7 @@ func (disc *Client) stopSync() {
340340
func (disc *Client) Quit() {
341341
_ = disc.sendCommand("QUIT\n")
342342
if _, err := disc.waitMessage(time.Second * 5); err != nil {
343-
disc.logger.Errorf("Quitting discovery %s: %s", disc.id, err)
343+
disc.logger.Errorf("Quitting discovery %s: %s", disc, err)
344344
}
345345
disc.stopSync()
346346
disc.killProcess()

0 commit comments

Comments
 (0)