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)