Skip to content

Commit

Permalink
backend: properly log and log logins
Browse files Browse the repository at this point in the history
  • Loading branch information
NickSavage committed Jan 3, 2025
1 parent 1c1f1b5 commit d95cb91
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions go-backend/handlers/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func (s *Handler) logCardView(cardPK int, userID int) {
}

func (s *Handler) LogLastLogin(user models.User) {
log.Printf("Successfully logged in for userID %v, username %v", user.ID, user.Username)
_, err := s.DB.Exec(`UPDATE users SET last_login = NOW() WHERE id = $1`, user.ID)
if err != nil {
// Log the error
Expand Down
14 changes: 9 additions & 5 deletions go-backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,15 @@ func addRoute(r *mux.Router, path string, handler http.HandlerFunc, method strin
}

func main() {
// file, err := handlers.OpenLogFile(os.Getenv("ZETTEL_BACKEND_LOG_LOCATION"))
// if err != nil {
// log.Fatal(err)
// }
// log.SetOutput(file)
// Set up logging based on environment
if os.Getenv("ZETTEL_DEV") != "true" {
file, err := handlers.OpenLogFile(os.Getenv("ZETTEL_BACKEND_LOG_LOCATION"))
if err != nil {
log.Fatal(err)
}
log.SetOutput(file)
}

s = &server.Server{}

dbConfig := models.DatabaseConfig{}
Expand Down

0 comments on commit d95cb91

Please sign in to comment.