added backend logs

This commit is contained in:
2026-01-18 10:34:31 +00:00
parent 282a286958
commit e384223f13
3 changed files with 13 additions and 3 deletions

1
.gitignore vendored
View File

@@ -4,7 +4,6 @@ backend/token/
# Logs # Logs
logs logs
nginx-log
*.log *.log
npm-debug.log* npm-debug.log*
yarn-debug.log* yarn-debug.log*

View File

@@ -2,6 +2,7 @@ package main
import ( import (
"fmt" "fmt"
"io"
"log" "log"
"os" "os"
"time" "time"
@@ -13,6 +14,16 @@ import (
) )
func main() { func main() {
r := gin.Default()
logsDir := "/backend/logs"
logFile, err := os.OpenFile(logsDir+"/go.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
panic(err)
}
gin.DefaultWriter = io.MultiWriter(os.Stdout, logFile)
r.Use(gin.Logger(), gin.Recovery())
dbUser := os.Getenv("POSTGRES_USER") dbUser := os.Getenv("POSTGRES_USER")
dbPassword := os.Getenv("POSTGRES_PASSWORD") dbPassword := os.Getenv("POSTGRES_PASSWORD")
dbName := os.Getenv("POSTGRES_DB") dbName := os.Getenv("POSTGRES_DB")
@@ -45,7 +56,6 @@ func main() {
store := handlers.Store{DB: db, SpotifyAuth: spotifyAuth, SpotifyClient: client, Auth: auth, Notes: notes} store := handlers.Store{DB: db, SpotifyAuth: spotifyAuth, SpotifyClient: client, Auth: auth, Notes: notes}
r := gin.Default()
protected := r.Group("/", store.AuthMiddlewear) protected := r.Group("/", store.AuthMiddlewear)
r.GET("/posts", store.GetPosts) r.GET("/posts", store.GetPosts)

View File

@@ -24,7 +24,7 @@ services:
volumes: volumes:
- ./certbot/conf:/etc/letsencrypt - ./certbot/conf:/etc/letsencrypt
- ./certbot/www:/var/www/certbot - ./certbot/www:/var/www/certbot
- ./nginx-log:/var/log/nginx - ./logs:/var/log/nginx
certbot: certbot:
image: certbot/certbot image: certbot/certbot
@@ -61,6 +61,7 @@ services:
volumes: volumes:
- ./backend/token/:/backend/token - ./backend/token/:/backend/token
- ${OBSIDIAN_DIR}:/backend/notes - ${OBSIDIAN_DIR}:/backend/notes
- ./logs:/backend/logs
db: db:
image: postgres:16 image: postgres:16