Mise à jour des scripts et docs de log
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import os
|
||||
import time
|
||||
|
||||
# 📁 Dossier contenant les fichiers de logs
|
||||
DOSSIER_LOGS = "/var/log"
|
||||
|
||||
# 📌 Récupère tous les .log du dossier (récursivement si besoin)
|
||||
import os
|
||||
import time
|
||||
|
||||
# 📁 Répertoire de logs à analyser
|
||||
DOSSIER_LOGS = "/var/log"
|
||||
|
||||
# 🔍 Demande un filtre à l'utilisateur
|
||||
filtre = input("🔎 Entrer un mot-clé pour filtrer les fichiers logs (ex: 'meudon', 'streamlit') : ").lower()
|
||||
|
||||
# 📋 Recherche récursive des fichiers .log
|
||||
fichiers_logs = []
|
||||
for racine, _, fichiers in os.walk(DOSSIER_LOGS):
|
||||
for fichier in fichiers:
|
||||
if fichier.endswith(".log"):
|
||||
chemin_complet = os.path.join(racine, fichier)
|
||||
if filtre in fichier.lower() or filtre in chemin_complet.lower():
|
||||
fichiers_logs.append(chemin_complet)
|
||||
|
||||
# 🛑 Aucun résultat ?
|
||||
if not fichiers_logs:
|
||||
print(f"Aucun fichier .log correspondant à '{filtre}' trouvé.")
|
||||
exit(1)
|
||||
|
||||
# 📑 Affiche les résultats filtrés
|
||||
print(f"\n📄 Logs trouvés correspondant à '{filtre}':\n")
|
||||
for i, fichier in enumerate(fichiers_logs):
|
||||
print(f"[{i}] {fichier}")
|
||||
|
||||
# ✅ Choix utilisateur
|
||||
try:
|
||||
choix = int(input("\nChoisir le numéro du log à surveiller : "))
|
||||
log_file = fichiers_logs[choix]
|
||||
except (ValueError, IndexError):
|
||||
print("❌ Choix invalide.")
|
||||
exit(1)
|
||||
|
||||
# 🔄 Affichage en temps réel (tail -f like)
|
||||
print(f"\n🔍 Surveillance de : {log_file} (Ctrl+C pour quitter)\n")
|
||||
with open(log_file, "r") as f:
|
||||
f.seek(0, os.SEEK_END)
|
||||
try:
|
||||
while True:
|
||||
ligne = f.readline()
|
||||
if ligne:
|
||||
print(ligne.strip())
|
||||
else:
|
||||
time.sleep(0.5)
|
||||
except KeyboardInterrupt:
|
||||
print("\n⏹️ Surveillance arrêtée.")
|
||||
|
||||
Reference in New Issue
Block a user