api: prettify verbose mode output

pull/311/head
Demian 4 years ago
parent 86d87415bd
commit 09b2f90c72

@ -40,11 +40,20 @@ func (b *Bot) Raw(method string, payload interface{}) ([]byte, error) {
} }
if b.verbose { if b.verbose {
log.Printf(`[verbose] telebot: sent request body, _ := json.Marshal(payload)
Method: %v body = bytes.ReplaceAll(body, []byte(`\"`), []byte(`"`))
URL: %v body = bytes.ReplaceAll(body, []byte(`"{`), []byte(`{`))
Params: %v body = bytes.ReplaceAll(body, []byte(`}"`), []byte(`}`))
Response: %v`, method, strings.Replace(url, b.Token, "<token>", -1), payload, string(data))
indent := func(b []byte) string {
buf.Reset()
json.Indent(&buf, b, "", "\t")
return buf.String()
}
log.Printf("[verbose] telebot: sent request\n"+
"Method: %v\nParams: %v\nResponse: %v",
method, indent(body), indent(data))
} }
// returning data as well // returning data as well

@ -93,8 +93,8 @@ type Settings struct {
// It makes ProcessUpdate return after the handler is finished. // It makes ProcessUpdate return after the handler is finished.
Synchronous bool Synchronous bool
// Verbose mode let you to debug the bot // Verbose forces bot to log all upcoming requests.
// Shows upcoming requests // Use for debugging purposes only.
Verbose bool Verbose bool
// ParseMode used to set default parse mode of all sent messages. // ParseMode used to set default parse mode of all sent messages.

Loading…
Cancel
Save