Skip to content

Commit

Permalink
api: prettify verbose mode output
Browse files Browse the repository at this point in the history
  • Loading branch information
demget committed Jun 9, 2020
1 parent 86d8741 commit 09b2f90
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
19 changes: 14 additions & 5 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 09b2f90

Please sign in to comment.