modified: app.py

modified:   templates/logs.html
This commit is contained in:
SimolZimol
2024-09-03 13:16:18 +02:00
parent e547c6e141
commit d59e1bff21
2 changed files with 34 additions and 0 deletions

21
app.py
View File

@@ -167,5 +167,26 @@ def download_logs():
return send_file(LOG_FILE_PATH, as_attachment=True)
return redirect(url_for("login"))
import shutil
ARCHIVE_DIR = "archive_logs"
if not os.path.exists(ARCHIVE_DIR):
os.makedirs(ARCHIVE_DIR)
@app.route("/archive_logs", methods=["POST"])
def archive_logs():
"""Archiviert die aktuelle Log-Datei und beginnt eine neue Log-Datei."""
if "username" in session:
if os.path.exists(LOG_FILE_PATH):
timestamp = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
archive_file = os.path.join(ARCHIVE_DIR, f"log_{timestamp}.log")
shutil.move(LOG_FILE_PATH, archive_file)
with open(LOG_FILE_PATH, 'w', encoding='utf-8') as file:
file.write("") # Neue leere Log-Datei starten
return jsonify({"status": "success", "message": "Logs archived successfully."})
else:
return jsonify({"status": "error", "message": "Log file not found."})
return redirect(url_for("login"))
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000, debug=True)