Skip to content

Commit 94e0e87

Browse files
committed
fix: switch to logus logging
1 parent 06c2d99 commit 94e0e87

File tree

4 files changed

+26
-45
lines changed

4 files changed

+26
-45
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,20 @@ import (
3636
func main() {
3737
bot, err := tgbotapi.NewBotAPI("MyAwesomeBotToken")
3838
if err != nil {
39-
log.Panic(err)
39+
logus.Panic(err)
4040
}
4141

4242
bot.Debug = true
4343

44-
log.Printf("Authorized on account %s", bot.Self.UserName)
44+
logus.Printf("Authorized on account %s", bot.Self.UserName)
4545

4646
u := tgbotapi.NewUpdate(0)
4747
u.Timeout = 60
4848

4949
updates, err := bot.GetUpdatesChan(u)
5050

5151
for update := range updates {
52-
log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text)
52+
logus.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text)
5353

5454
msg := tgbotapi.NewMessage(update.Message.Chat.ID, update.Message.Text)
5555
msg.ReplyToMessageID = update.Message.MessageID
@@ -74,23 +74,23 @@ import (
7474
func main() {
7575
bot, err := tgbotapi.NewBotAPI("MyAwesomeBotToken")
7676
if err != nil {
77-
log.Fatal(err)
77+
logus.Fatal(err)
7878
}
7979

8080
bot.Debug = true
8181

82-
log.Printf("Authorized on account %s", bot.Self.UserName)
82+
logus.Printf("Authorized on account %s", bot.Self.UserName)
8383

8484
_, err = bot.SetWebhook(tgbotapi.NewWebhookWithCert("https://www.google.com:8443/"+bot.Token, "cert.pem"))
8585
if err != nil {
86-
log.Fatal(err)
86+
logus.Fatal(err)
8787
}
8888

8989
updates, _ := bot.ListenForWebhook("/" + bot.Token)
9090
go http.ListenAndServeTLS("0.0.0.0:8443", "cert.pem", "key.pem", nil)
9191

9292
for update := range updates {
93-
log.Printf("%+v\n", update)
93+
logus.Printf("%+v\n", update)
9494
}
9595
}
9696
```

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
module github.com/bots-go-framework/bots-api-telegram
22

3-
go 1.21
3+
go 1.22.3
44

55
toolchain go1.22.4
66

77
require (
88
github.com/bots-go-framework/bots-go-core v0.0.2
99
github.com/pquerna/ffjson v0.0.0-20190930134022-aa0246cd15f7
1010
github.com/stretchr/testify v1.9.0
11-
github.com/strongo/log v0.3.0
11+
github.com/strongo/logus v0.0.0-20240628225821-04cf45b5968f
1212
github.com/technoweenie/multipartstreamer v1.0.1
1313
)
1414

go.sum

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
github.com/bots-go-framework/bots-go-core v0.0.1 h1:Br7j+Ir3R6U8x1mnFZFq1G1K0bupJhLvdF8TIqI/7i8=
2-
github.com/bots-go-framework/bots-go-core v0.0.1/go.mod h1:txRZn1MlcJEiCUra3bQtpkt9IM2EFGaeUvqS1VLyl30=
31
github.com/bots-go-framework/bots-go-core v0.0.2 h1:3F/czNOLZCO5rco1Zr9rATLvJrze5PZpa2dMRv4ON+M=
42
github.com/bots-go-framework/bots-go-core v0.0.2/go.mod h1:u4r0W8t+n/07ulLlPZT3rdCt+mb5WHXP72z4oeTJVN0=
53
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
6-
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
74
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
85
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
96
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
@@ -20,30 +17,14 @@ github.com/pquerna/ffjson v0.0.0-20190930134022-aa0246cd15f7 h1:xoIK0ctDddBMnc74
2017
github.com/pquerna/ffjson v0.0.0-20190930134022-aa0246cd15f7/go.mod h1:YARuvh7BUWHNhzDq2OM5tzR2RiCcN2D7sapiKyCel/M=
2118
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
2219
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
23-
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
24-
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
25-
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
26-
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
27-
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
28-
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
29-
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
30-
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
31-
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
32-
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
33-
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
3420
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
3521
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
36-
github.com/strongo/log v0.0.2 h1:8ZCCfGbq0SX8AyUklcqHxajMXj1/OaPS1a/G6LMzUB8=
37-
github.com/strongo/log v0.0.2/go.mod h1:C0OyprbH7WjyhcZXdveDiu5n0vxB8qZ1rQXxtUqx8y4=
38-
github.com/strongo/log v0.2.3 h1:Qc3YoNUYvZjCxwHdfl0Ne/XUCQfpxAyYJDucsy5PmCI=
39-
github.com/strongo/log v0.2.3/go.mod h1:C0OyprbH7WjyhcZXdveDiu5n0vxB8qZ1rQXxtUqx8y4=
40-
github.com/strongo/log v0.3.0 h1:89rh62SdO9TNTd8/pzhMSdGCmZwFDXHWm5ZtJvp0Wcg=
41-
github.com/strongo/log v0.3.0/go.mod h1:C0OyprbH7WjyhcZXdveDiu5n0vxB8qZ1rQXxtUqx8y4=
22+
github.com/strongo/logus v0.0.0-20240628225821-04cf45b5968f h1:U+ikeZnsuwnmzU0KKEo9W+DA899Sf5ZDKvuiHKDFHf8=
23+
github.com/strongo/logus v0.0.0-20240628225821-04cf45b5968f/go.mod h1:sd8gjJklqGQAg+Q0mlP5MWgzguAuxR25YYFSkfVOPdc=
4224
github.com/technoweenie/multipartstreamer v1.0.1 h1:XRztA5MXiR1TIRHxH2uNxXxaIkKQDeX7m2XsSOlQEnM=
4325
github.com/technoweenie/multipartstreamer v1.0.1/go.mod h1:jNVxdtShOxzAsukZwTSw6MDx5eUJoiEBsSvzDU9uzog=
4426
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
4527
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
4628
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
47-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
4829
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
4930
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

tgbotapi/bot.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"errors"
1010
"fmt"
1111
"github.com/pquerna/ffjson/ffjson"
12-
"github.com/strongo/log"
12+
"github.com/strongo/logus"
1313
"github.com/technoweenie/multipartstreamer"
1414
"io"
1515
"net/http"
@@ -75,7 +75,7 @@ func (bot *BotAPI) MakeRequest(endpoint string, params url.Values) (apiResp APIR
7575
if resp, err = bot.Client.PostForm(method, params); err != nil {
7676
if strings.Contains(err.Error(), "DEADLINE_EXCEEDED") {
7777
hadDeadlineExceeded = true
78-
log.Warningf(bot.c, "#%v fail to send POST due to DEADLINE_EXCEEDED to %v, will retry: %v", i, method, err)
78+
logus.Warningf(bot.c, "#%v fail to send POST due to DEADLINE_EXCEEDED to %v, will retry: %v", i, method, err)
7979
continue
8080
}
8181
}
@@ -84,21 +84,21 @@ func (bot *BotAPI) MakeRequest(endpoint string, params url.Values) (apiResp APIR
8484
if resp != nil && resp.Body != nil {
8585
defer func() {
8686
if err := resp.Body.Close(); err != nil {
87-
log.Warningf(bot.c, "failed to close response body: %v", err)
87+
logus.Warningf(bot.c, "failed to close response body: %v", err)
8888
}
8989
}()
9090
}
9191

9292
if err != nil {
93-
log.Errorf(bot.c, "Failed to send POST to %v: %v", method, err.Error())
93+
logus.Errorf(bot.c, "Failed to send POST to %v: %v", method, err.Error())
9494
return APIResponse{Ok: false}, fmt.Errorf("%v: %s: %w", "POST", method, err)
9595
}
9696

9797
var body []byte
9898
if resp.ContentLength > 0 {
9999
var readerErr error
100100
if body, readerErr = io.ReadAll(resp.Body); err != nil {
101-
log.Errorf(bot.c, "Failed to read response.body: %v", readerErr)
101+
logus.Errorf(bot.c, "Failed to read response.body: %v", readerErr)
102102
if err == nil {
103103
err = readerErr
104104
}
@@ -124,8 +124,8 @@ func (bot *BotAPI) MakeRequest(endpoint string, params url.Values) (apiResp APIR
124124

125125
logRequestAndResponse := func() {
126126
if bot.c != nil {
127-
log.Debugf(bot.c, "Request to Telegram API: %v => %v", endpoint, params)
128-
log.Debugf(bot.c, "Telegram API response: %v", string(body))
127+
logus.Debugf(bot.c, "Request to Telegram API: %v => %v", endpoint, params)
128+
logus.Debugf(bot.c, "Telegram API response: %v", string(body))
129129
}
130130
}
131131

@@ -248,7 +248,7 @@ func (bot *BotAPI) UploadFile(endpoint string, params map[string]string, fieldna
248248
}
249249

250250
if bot.c != nil {
251-
log.Debugf(bot.c, string(body))
251+
logus.Debugf(bot.c, string(body))
252252
}
253253

254254
var apiResp APIResponse
@@ -336,11 +336,11 @@ func (bot *BotAPI) Send(c Chattable) (Message, error) {
336336

337337
// debugLog checks if the bot is currently running in debug mode, and if
338338
// so will display information about the request and response in the
339-
// debug log.
339+
// debug logus.
340340
func (bot *BotAPI) debugLog(context string, v url.Values, message interface{}) {
341341
if bot.c != nil {
342-
log.Debugf(bot.c, "%s req : %+v\n", context, v)
343-
log.Debugf(bot.c, "%s resp: %+v\n", context, message)
342+
logus.Debugf(bot.c, "%s req : %+v\n", context, v)
343+
logus.Debugf(bot.c, "%s resp: %+v\n", context, message)
344344
}
345345
}
346346

@@ -522,7 +522,7 @@ func (bot *BotAPI) SetWebhook(config WebhookConfig) (APIResponse, error) {
522522
}
523523

524524
if bot.c != nil {
525-
log.Debugf(bot.c, "setWebhook resp: %+v\n", apiResp)
525+
logus.Debugf(bot.c, "setWebhook resp: %+v\n", apiResp)
526526
}
527527

528528
return apiResp, nil
@@ -537,8 +537,8 @@ func (bot *BotAPI) GetUpdatesChan(config *UpdateConfig) (<-chan Update, error) {
537537
for {
538538
updates, err := bot.GetUpdates(config)
539539
if err != nil {
540-
//log.Println(err)
541-
//log.Println("Failed to get updates, retrying in 3 seconds...")
540+
//logus.Println(err)
541+
//logus.Println("Failed to get updates, retrying in 3 seconds...")
542542
time.Sleep(time.Second * 3)
543543

544544
continue
@@ -565,7 +565,7 @@ func (bot *BotAPI) ListenForWebhook(pattern string) <-chan Update {
565565

566566
var update Update
567567
if err := ffjson.Unmarshal(body, &update); err != nil {
568-
log.Errorf(context.Background(), fmt.Errorf("failed to unmarshal update JSON: %w", err).Error())
568+
logus.Errorf(context.Background(), fmt.Errorf("failed to unmarshal update JSON: %w", err).Error())
569569
return
570570
}
571571

0 commit comments

Comments
 (0)