Ajout de visualiseur de fichiers Logs

This commit is contained in:
2025-07-27 10:02:24 +02:00
parent 51bafc1b09
commit 0f607cbf17
2 changed files with 56 additions and 0 deletions

53
app/visualiseur_logs.py Normal file
View File

@@ -0,0 +1,53 @@
import streamlit as st
import os
import platform
# 🟢 CECI DOIT ÊTRE LA PREMIÈRE COMMANDE STREAMLIT !
st.set_page_config(page_title="Visualiseur de Logs", layout="wide")
# 🔧 Détection du bon dossier selon l'OS
if platform.system() == "Windows":
LOG_DIR = "C:/Users/miche/PycharmProjects/Gestion_sondes/Logs"
else:
LOG_DIR = "/home/debian/Gestion_sondes/Logs"
# Titre
st.title("🧾 Visualiseur de fichiers logs")
# Liste des fichiers .log ou similaires
try:
fichiers = sorted(
[f for f in os.listdir(LOG_DIR) if ".log" in f],
key=lambda x: os.path.getmtime(os.path.join(LOG_DIR, x)),
reverse=True
)
except FileNotFoundError:
st.error(f"📁 Dossier introuvable : {LOG_DIR}")
st.stop()
if not fichiers:
st.warning("Aucun fichier log trouvé dans le dossier.")
st.stop()
# Choix du fichier
choix = st.selectbox("📂 Sélectionnez un fichier log :", fichiers)
log_path = os.path.join(LOG_DIR, choix)
# Options d'affichage
col1, col2 = st.columns([1, 1])
with col1:
filtre_erreurs = st.checkbox("🔍 Afficher uniquement les erreurs", value=False)
with col2:
nb_lignes = st.slider("📏 Nombre de lignes à afficher", 10, 5000, 300)
# Lecture du fichier
with open(log_path, "r", encoding="utf-8", errors="ignore") as f:
lignes = f.readlines()
if filtre_erreurs:
mots_cles = ["ERROR", "", "Traceback", "failed", "exception"]
lignes = [l for l in lignes if any(m in l.lower() for m in mots_cles)]
# Affichage
dernieres = lignes[-nb_lignes:]
st.text_area("📄 Contenu du fichier log :", "".join(dernieres), height=600)

View File

@@ -3,6 +3,9 @@
# Variables # Variables
DATE=$(date +'%Y-%m-%d_%H-%M') DATE=$(date +'%Y-%m-%d_%H-%M')
BACKUP_DIR="/home/debian/backup" BACKUP_DIR="/home/debian/backup"
LOG_DIR="/home/debian/Gestion_sondes/Logs"
LOG_FILE="$LOG_DIR/backup_$DATE.log"
exec > "$LOG_FILE" 2>&1
BACKUP_FILE="$BACKUP_DIR/mysql_backup_$DATE.sql" BACKUP_FILE="$BACKUP_DIR/mysql_backup_$DATE.sql"
NAS_HOST="mon-nas" # défini dans /home/debian/.ssh/config NAS_HOST="mon-nas" # défini dans /home/debian/.ssh/config
MYSQL_USER="root" MYSQL_USER="root"