Replace log package with slog for structured logging and improve error handling
This commit is contained in:
@@ -7,7 +7,7 @@ import (
|
||||
"CatsOfMastodonBotGo/internal/server"
|
||||
"CatsOfMastodonBotGo/internal/services"
|
||||
"context"
|
||||
"log"
|
||||
"log/slog"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -30,7 +30,7 @@ func main() {
|
||||
var posts []domain.Post = nil
|
||||
err, posts := services.PostServiceInstance.GetPostsFromApi(ctx, config.Config.Tag, config.Config.Instance)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
slog.Error(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
@@ -40,14 +40,14 @@ func main() {
|
||||
var newAccounts = services.PostServiceInstance.GetNewAccounts(existingAccountIds, newPosts)
|
||||
|
||||
// Save to database
|
||||
log.Printf("Fetched %d posts; %d existing posts; %d new posts and %d new accounts\n", len(posts), len(existingPostIds), len(newPosts), len(newAccounts))
|
||||
slog.Info("Fetched %d posts; %d existing posts; %d new posts and %d new accounts\n", len(posts), len(existingPostIds), len(newPosts), len(newAccounts))
|
||||
|
||||
// Additional logging
|
||||
if newAccounts != nil {
|
||||
log.Printf("Inserted %d accounts\n", services.PostServiceInstance.InsertNewAccounts(newAccounts))
|
||||
slog.Info("Inserted %d accounts\n", services.PostServiceInstance.InsertNewAccounts(newAccounts))
|
||||
}
|
||||
if newPosts != nil {
|
||||
log.Printf("Inserted %d posts\n", services.PostServiceInstance.InsertNewPosts(newPosts))
|
||||
slog.Info("Inserted %d posts\n", services.PostServiceInstance.InsertNewPosts(newPosts))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ func main() {
|
||||
r := server.SetupRouter()
|
||||
err := r.Run(":8080")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
slog.Error(err.Error())
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user