Fix #17. Implementing slog-based logger for telego and passing it into the library.
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
Alexey Skobkin 2024-03-12 23:05:52 +03:00
parent d3c0bc28f1
commit 3fa7c2434f
No known key found for this signature in database
GPG key ID: 5D5CEF6F221278E7
2 changed files with 25 additions and 1 deletions

24
bot/logger.go Normal file
View file

@ -0,0 +1,24 @@
package bot
import (
"fmt"
"log/slog"
)
type Logger struct {
prefix string
}
func NewLogger(prefix string) Logger {
return Logger{
prefix: prefix,
}
}
func (l Logger) Debugf(format string, args ...any) {
slog.Debug(l.prefix + fmt.Sprint(format, args))
}
func (l Logger) Errorf(format string, args ...any) {
slog.Error(l.prefix + fmt.Sprintf(format, args))
}

View file

@ -20,7 +20,7 @@ func main() {
llmc := llm.NewConnector(ollamaBaseUrl, ollamaToken)
ext := extractor.NewExtractor()
telegramApi, err := tg.NewBot(telegramToken, tg.WithDefaultLogger(false, true))
telegramApi, err := tg.NewBot(telegramToken, tg.WithLogger(bot.NewLogger("telego: ")))
if err != nil {
fmt.Println(err)
os.Exit(1)