veza/scripts/rotate_logs.sh
senke 17a04a6b2e feat: centraliser tous les logs dans /var/log/veza avec rotation
- Configure LOG_DIR=/var/log/veza pour tous les services
- Ajoute scripts de gestion des logs (setup, view, rotate)
- Configure volume Docker partagé pour les logs
- Logs organisés par service avec fichiers séparés pour les erreurs
- Rotation automatique : 100MB, 10 backups, 30 jours, compression gzip
- Documentation dans LOGGING.md et ENV_CONFIG.md

Services configurés:
- Backend API: backend-api.log, redis.log, db.log, rabbitmq.log
- Chat Server: chat-server.log (à configurer)
- Stream Server: stream-server.log (à configurer)

Le backend API a déjà toute l'infrastructure de logging en place.
Les serveurs chat et stream utiliseront LOG_DIR depuis l'environnement.
2026-01-04 01:44:23 +01:00

101 lines
3.1 KiB
Bash
Executable file

#!/bin/bash
# Script pour gérer la rotation manuelle des logs Veza
# Usage: bash scripts/rotate_logs.sh [service]
#
# Services disponibles:
# backend-api, redis, db, rabbitmq, chat-server, stream-server, all
set -e
LOG_DIR="/var/log/veza"
SERVICE="${1:-all}"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
rotate_file() {
local file="$1"
local label="$2"
if [ ! -f "$file" ]; then
echo "⚠️ Fichier $file non trouvé, ignoré"
return
fi
local size=$(du -h "$file" | cut -f1)
echo "🔄 Rotation de $label ($size)..."
# Créer une copie avec timestamp
cp "$file" "${file}.${TIMESTAMP}"
# Compresser l'ancien fichier
gzip "${file}.${TIMESTAMP}"
# Vider le fichier actuel
> "$file"
echo "$label roté vers ${file}.${TIMESTAMP}.gz"
}
case $SERVICE in
backend-api)
rotate_file "$LOG_DIR/backend-api.log" "Backend API"
rotate_file "$LOG_DIR/backend-api-error.log" "Backend API Errors"
;;
redis)
rotate_file "$LOG_DIR/redis.log" "Redis"
rotate_file "$LOG_DIR/redis-error.log" "Redis Errors"
;;
db)
rotate_file "$LOG_DIR/db.log" "Database"
rotate_file "$LOG_DIR/db-error.log" "Database Errors"
;;
rabbitmq)
rotate_file "$LOG_DIR/rabbitmq.log" "RabbitMQ"
rotate_file "$LOG_DIR/rabbitmq-error.log" "RabbitMQ Errors"
;;
chat-server)
rotate_file "$LOG_DIR/chat-server.log" "Chat Server"
rotate_file "$LOG_DIR/chat-server-error.log" "Chat Server Errors"
;;
stream-server)
rotate_file "$LOG_DIR/stream-server.log" "Stream Server"
rotate_file "$LOG_DIR/stream-server-error.log" "Stream Server Errors"
;;
all)
echo "🔄 Rotation de tous les logs Veza..."
echo ""
rotate_file "$LOG_DIR/backend-api.log" "Backend API"
rotate_file "$LOG_DIR/backend-api-error.log" "Backend API Errors"
rotate_file "$LOG_DIR/redis.log" "Redis"
rotate_file "$LOG_DIR/redis-error.log" "Redis Errors"
rotate_file "$LOG_DIR/db.log" "Database"
rotate_file "$LOG_DIR/db-error.log" "Database Errors"
rotate_file "$LOG_DIR/rabbitmq.log" "RabbitMQ"
rotate_file "$LOG_DIR/rabbitmq-error.log" "RabbitMQ Errors"
rotate_file "$LOG_DIR/chat-server.log" "Chat Server"
rotate_file "$LOG_DIR/chat-server-error.log" "Chat Server Errors"
rotate_file "$LOG_DIR/stream-server.log" "Stream Server"
rotate_file "$LOG_DIR/stream-server-error.log" "Stream Server Errors"
echo ""
echo "✅ Rotation terminée!"
;;
*)
echo "❌ Service inconnu: $SERVICE"
echo ""
echo "Services disponibles:"
echo " - backend-api"
echo " - redis"
echo " - db"
echo " - rabbitmq"
echo " - chat-server"
echo " - stream-server"
echo " - all"
exit 1
;;
esac
echo ""
echo "📊 Fichiers de logs actuels:"
ls -lh "$LOG_DIR"/*.log 2>/dev/null || echo "Aucun fichier actif"
echo ""
echo "📦 Archives compressées:"
ls -lh "$LOG_DIR"/*.gz 2>/dev/null || echo "Aucune archive"