From 3fa7c2434fdb26c77857608645109f29e2bc8610 Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Tue, 12 Mar 2024 23:05:52 +0300 Subject: [PATCH] Fix #17. Implementing slog-based logger for telego and passing it into the library. --- bot/logger.go | 24 ++++++++++++++++++++++++ main.go | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 bot/logger.go diff --git a/bot/logger.go b/bot/logger.go new file mode 100644 index 0000000..7089e8d --- /dev/null +++ b/bot/logger.go @@ -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)) +} diff --git a/main.go b/main.go index e184ea3..6611c9a 100644 --- a/main.go +++ b/main.go @@ -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)