fix: use docker logs instead of log file for debug API
This commit is contained in:
parent
ba20630033
commit
cbc60a08e4
31
admin_api.py
31
admin_api.py
|
|
@ -365,34 +365,33 @@ def debug_management():
|
||||||
|
|
||||||
# ===== view-logs =====
|
# ===== view-logs =====
|
||||||
if action == 'view-logs':
|
if action == 'view-logs':
|
||||||
log_file = current_app.config.get('LOG_FILE', '/app/logs/spawner.log')
|
|
||||||
try:
|
try:
|
||||||
with open(log_file, 'r', encoding='utf-8') as f:
|
import subprocess
|
||||||
lines = f.readlines()
|
# Lese Docker Container Logs
|
||||||
last_100 = lines[-100:] if len(lines) > 100 else lines
|
result = subprocess.run(
|
||||||
|
['docker', 'logs', '--tail', '100', 'spawner'],
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
timeout=10
|
||||||
|
)
|
||||||
|
logs = result.stdout if result.returncode == 0 else result.stderr
|
||||||
|
|
||||||
return jsonify({
|
return jsonify({
|
||||||
'action': 'view-logs',
|
'action': 'view-logs',
|
||||||
'lines': len(lines),
|
'source': 'docker logs spawner',
|
||||||
'last_100': ''.join(last_100)
|
'lines': len(logs.split('\n')),
|
||||||
|
'logs': logs
|
||||||
}), 200
|
}), 200
|
||||||
except FileNotFoundError:
|
|
||||||
return jsonify({'error': 'Log-Datei nicht gefunden'}), 404
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return jsonify({'error': f'Fehler beim Lesen der Logs: {str(e)}'}), 500
|
return jsonify({'error': f'Fehler beim Lesen der Logs: {str(e)}'}), 500
|
||||||
|
|
||||||
# ===== clear-logs =====
|
# ===== clear-logs =====
|
||||||
elif action == 'clear-logs':
|
elif action == 'clear-logs':
|
||||||
log_file = current_app.config.get('LOG_FILE', '/app/logs/spawner.log')
|
|
||||||
try:
|
|
||||||
with open(log_file, 'w') as f:
|
|
||||||
f.write('')
|
|
||||||
current_app.logger.info('[DEBUG] Logs wurden gelöscht')
|
|
||||||
return jsonify({
|
return jsonify({
|
||||||
'action': 'clear-logs',
|
'action': 'clear-logs',
|
||||||
'message': 'Logs wurden gelöscht'
|
'message': 'Docker-Logs können nicht gelöscht werden',
|
||||||
|
'info': 'Nutze stattdessen: docker-compose logs -f spawner --tail 1'
|
||||||
}), 200
|
}), 200
|
||||||
except Exception as e:
|
|
||||||
return jsonify({'error': f'Fehler beim Löschen der Logs: {str(e)}'}), 500
|
|
||||||
|
|
||||||
# ===== delete-email =====
|
# ===== delete-email =====
|
||||||
elif action == 'delete-email':
|
elif action == 'delete-email':
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user