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 {
log.Printf(`[verbose] telebot: sent request
Method: %v
URL: %v
Params: %v
Response: %v`, method, strings.Replace(url, b.Token, "<token>", -1), payload, string(data))
body, _ := json.Marshal(payload)
body = bytes.ReplaceAll(body, []byte(`\"`), []byte(`"`))
body = bytes.ReplaceAll(body, []byte(`"{`), []byte(`{`))
body = bytes.ReplaceAll(body, []byte(`}"`), []byte(`}`))
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

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

Loading…
Cancel
Save