chore: share Truncate helper between mqtt and http trace logs (#31947)
This commit is contained in:
parent
8a8abdaede
commit
0b5017e7c1
2 changed files with 13 additions and 13 deletions
|
|
@ -242,7 +242,7 @@ func (m *Client) Publish(topic string, retained bool, payload string) {
|
|||
return
|
||||
}
|
||||
|
||||
m.log.TRACE.Printf("send %s: '%v'", topic, truncate(payload))
|
||||
m.log.TRACE.Printf("send %s: '%v'", topic, request.Truncate(payload))
|
||||
token := m.client.Publish(topic, m.Qos, retained, payload)
|
||||
|
||||
select {
|
||||
|
|
@ -290,7 +290,7 @@ func (m *Client) ListenSetter(topic string, callback func(string) error) error {
|
|||
func (m *Client) listen(topic string) paho.Token {
|
||||
token := m.client.Subscribe(topic, m.Qos, func(c paho.Client, msg paho.Message) {
|
||||
payload := string(msg.Payload())
|
||||
m.log.TRACE.Printf("recv %s: '%v'", topic, truncate(payload))
|
||||
m.log.TRACE.Printf("recv %s: '%v'", topic, request.Truncate(payload))
|
||||
if len(payload) > 0 {
|
||||
m.mux.Lock()
|
||||
callbacks := m.listener[topic]
|
||||
|
|
@ -303,11 +303,3 @@ func (m *Client) listen(topic string) paho.Token {
|
|||
})
|
||||
return token
|
||||
}
|
||||
|
||||
// truncate limits payload length in trace logs, matching HTTP logging
|
||||
func truncate(s string) string {
|
||||
if len(s) > request.LogMaxLen {
|
||||
s = s[:request.LogMaxLen] + "..."
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue