@@ -7,13 +7,11 @@ import (
77
88 "github.com/go-faster/errors"
99 "github.com/gotd/log"
10- "github.com/gotd/log/logzap"
1110 "github.com/gotd/td/telegram"
1211 "github.com/gotd/td/telegram/message"
1312 "github.com/gotd/td/telegram/peers"
1413 "github.com/gotd/td/telegram/updates"
1514 "github.com/gotd/td/tg"
16- "go.uber.org/zap"
1715)
1816
1917// Bot is a Telegram Bot API client implemented over MTProto.
@@ -22,7 +20,7 @@ import (
2220// Run to connect and serve. Bot is safe for concurrent use once running.
2321type Bot struct {
2422 token string
25- log * zap .Logger
23+ log log .Logger
2624
2725 client * telegram.Client
2826 raw * tg.Client
@@ -60,9 +58,7 @@ func New(token string, opt Options) (*Bot, error) {
6058 return nil , errors .New ("AppID and AppHash are required (see https://my.telegram.org)" )
6159 }
6260 opt .setDefaults ()
63-
64- // gotd/td logs through the github.com/gotd/log port; bridge the zap logger.
65- lg := logzap .New (opt .Logger )
61+ lg := opt .Logger
6662
6763 disp := tg .NewUpdateDispatcher ()
6864
@@ -83,7 +79,7 @@ func New(token string, opt Options) (*Bot, error) {
8379 AccessHasher : pm ,
8480 Logger : log .Named (lg , "gaps" ),
8581 OnChannelTooLong : func (channelID int64 ) {
86- opt . Logger .Warn ("Channel too long" , zap .Int64 ("channel_id" , channelID ))
82+ log . For ( lg ) .Warn (context . Background (), "Channel too long" , log .Int64 ("channel_id" , channelID ))
8783 },
8884 })
8985
@@ -146,10 +142,10 @@ func (b *Bot) publishCommands(ctx context.Context) {
146142 return
147143 }
148144 if err := b .SetMyCommands (ctx , cmds ); err != nil {
149- b .log .Warn ("Register bot commands" , zap .Error (err ))
145+ b .logger () .Warn (ctx , "Register bot commands" , log .Error (err ))
150146 return
151147 }
152- b .log .Debug ("Registered bot commands" , zap .Int ("count" , len (cmds )))
148+ b .logger () .Debug (ctx , "Registered bot commands" , log .Int ("count" , len (cmds )))
153149}
154150
155151// Run connects, authorizes as a bot, and blocks serving updates until ctx is
@@ -187,9 +183,9 @@ func (b *Bot) Run(ctx context.Context) error {
187183 return b .gaps .Run (ctx , b .raw , me .ID , updates.AuthOptions {
188184 IsBot : true ,
189185 OnStart : func (ctx context.Context ) {
190- b .log .Info ("Bot started" ,
191- zap .Int64 ("id" , me .ID ),
192- zap .String ("username" , me .Username ),
186+ b .logger () .Info (ctx , "Bot started" ,
187+ log .Int64 ("id" , me .ID ),
188+ log .String ("username" , me .Username ),
193189 )
194190 b .publishCommands (ctx )
195191 if b .onStart != nil {
@@ -218,8 +214,11 @@ func (b *Bot) Peers() *peers.Manager { return b.peers }
218214// Self returns the bot's own user. It is nil until Run has authorized.
219215func (b * Bot ) Self () * tg.User { return b .self }
220216
221- // Logger returns the bot's zap logger.
222- func (b * Bot ) Logger () * zap.Logger { return b .log }
217+ // Logger returns the bot's structured logger (the github.com/gotd/log port).
218+ func (b * Bot ) Logger () log.Logger { return b .log }
219+
220+ // logger wraps the bot's logger in an ergonomic Helper for internal logging.
221+ func (b * Bot ) logger () log.Helper { return log .For (b .log ) }
223222
224223func (b * Bot ) setRunCtx (ctx context.Context ) {
225224 b .runMu .Lock ()
0 commit comments