Add debug logging system with full request/response logging and sanitization

- New debug logging system with auto-sanitization of sensitive data (passwords, tokens, JWTs, keys)
- Debug mode can be enabled via launcher (option 6) or Server page UI
- Debug logs written to logs/debug.log with full HTTP request/response details
- Added comprehensive page access logging (overview, players, vehicles, server, director)
- Added SSH, K8s, database, and service initialization debug logging
- Fixed miner protection console spam (now uses DEBUG level)
- Removed admin management section from server page
- Updated README with debug mode documentation
This commit is contained in:
Reditus committed 2026-05-19 06:59:46 +01:00
1 parent e977f8cd5b
commit 00288d93a6
12 files changed
+662 -28

No files matched your search

+6 -1
View File
@@ -121,14 +121,19 @@ class DatabaseService:
try:
conn = self.get_connection()
if not conn:
logger.warning("Database health check: no connection available")
return False
cur = conn.cursor()
cur.execute('SELECT 1')
cur.fetchone()
cur.close()
self.return_connection(conn)
db_host = self.db_config.get('host', 'unknown')
db_port = self.db_config.get('port', 'unknown')
logger.debug(f"Database health check OK (host={db_host}, port={db_port})")
return True
except Exception:
except Exception as e:
logger.warning(f"Database health check FAILED: {e}")
return False
def ensure_tables(self):
+11 -2
View File
@@ -12,14 +12,23 @@ class K8sService:
def run(self, kubectl_command, timeout=30):
full_cmd = f'sudo kubectl {kubectl_command} -n {self.namespace}'
return self.ssh.run(full_cmd, timeout=timeout)
logger.debug(f"K8s executing: kubectl {kubectl_command} -n {self.namespace}")
result = self.ssh.run(full_cmd, timeout=timeout)
out, err, rc = result
if rc != 0:
logger.debug(f"K8s command failed (rc={rc}): {err[:100] if err else 'no error'}")
else:
logger.debug(f"K8s command OK, output lines: {len(out.split(chr(10))) if out else 0}")
return result
def get_pods(self):
out, err, rc = self.run('get pods -o name')
if rc != 0:
logger.error(f"Failed to get pods: {err}")
return []
return [line.replace('pod/', '').strip() for line in (out or '').strip().split('\n') if line.strip()]
pods = [line.replace('pod/', '').strip() for line in (out or '').strip().split('\n') if line.strip()]
logger.debug(f"Found {len(pods)} pods in namespace {self.namespace}")
return pods
def find_pod_by_pattern(self, pattern):
pods = self.get_pods()
+3 -3
View File
@@ -167,10 +167,10 @@ class MinerProtection:
if not self.enabled:
return
logger.info("Running miner protection check...")
logger.debug("Running miner protection check...")
result = self._cleanup_miner()
self._log_result(result)
logger.info(f"Miner check result: {result['status']} - {result['details']}")
logger.debug(f"Miner check result: {result['status']} - {result['details']}")
def _background_loop(self):
"""Background thread loop."""
@@ -178,7 +178,7 @@ class MinerProtection:
try:
self._run_check()
except Exception as e:
logger.error(f"Miner protection check failed: {e}")
logger.debug(f"Miner protection check failed: {e}")
time.sleep(self.interval)
def start(self):
+16 -3
View File
@@ -5,6 +5,7 @@ import threading
import paramiko
from app.utils.ssh_key import resolve_ssh_key
from app.utils.debug_logging import sanitize_for_log, log_ssh_command, log_ssh_result
logger = logging.getLogger(__name__)
@@ -77,23 +78,35 @@ class SSHService:
Returns:
Tuple of (stdout, stderr, return_code).
"""
logger.debug("SSH command: %s...", command[:100] if len(command) > 100 else command)
cmd_display = command[:150] + '...' if len(command) > 150 else command
logger.debug(f"SSH executing: {cmd_display}")
try:
client = self._get_client()
stdin, stdout, stderr = client.exec_command(command, timeout=timeout)
out = stdout.read().decode('utf-8', errors='replace')
err = stderr.read().decode('utf-8', errors='replace')
rc = stdout.channel.recv_exit_status()
# Debug logging for result
logger.debug(f"SSH result: host={self.host}, user={self.user}, rc={rc}, stdout_len={len(out)}, stderr_len={len(err)}")
if err and rc != 0:
logger.warning(f"SSH stderr (rc={rc}): {err[:200]}")
if out:
logger.debug(f"SSH stdout preview: {out[:200]}")
if rc != 0:
cmd_short = command[:80] + '...' if len(command) > 80 else command
logger.warning("SSH command failed (rc=%d): cmd=%s err=%s", rc, cmd_short, err[:100] if err else 'none')
return out, err, rc
except paramiko.SSHException as e:
logger.error("SSH command error: %s", e)
logger.error(f"SSH command error ({self.host}): {e}")
logger.debug(f"SSH error details: type={type(e).__name__}, args={e.args}")
self._client = None
return '', str(e), -1
except Exception as ex:
logger.error("Unexpected SSH command error: %s", ex)
logger.error(f"Unexpected SSH command error ({self.host}): {ex}")
logger.debug(f"SSH exception details: type={type(ex).__name__}, args={ex.args}")
self._client = None
return '', str(ex), -1