Fix #17. Implementing slog-based logger for telego and passing it into the library.
This commit is contained in:
parent
d3c0bc28f1
commit
3fa7c2434f
24
bot/logger.go
Normal file
24
bot/logger.go
Normal 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))
|
||||||
|
}
|
2
main.go
2
main.go
|
@ -20,7 +20,7 @@ func main() {
|
||||||
llmc := llm.NewConnector(ollamaBaseUrl, ollamaToken)
|
llmc := llm.NewConnector(ollamaBaseUrl, ollamaToken)
|
||||||
ext := extractor.NewExtractor()
|
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 {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
Loading…
Reference in a new issue