Files
TravianZ/Templates/debug_status.tpl
T
Ferywir 827354a622 feat(admin): add transparent debug error-log mode
Add an admin-controlled debug mode that captures PHP errors of all
players into var/log/debug-players.log, to hunt remaining PHP 8.3 bugs
from real play sessions. Fully transparent to players: no redirect, no
gameplay change, errors are never displayed.

- DB: new debug_log table (one row), mirroring the maintenance pattern.
- Database: getDebugMode()/setDebugMode()/setDebugSettings(), defensive
  when the table is absent (no blank page).
- Session: register a custom error + shutdown handler when enabled; the
  handler runs even when php.ini error_reporting masks warnings/notices,
  so capture is complete without a Docker rebuild. Auto-disables after a
  configurable window.
- DebugErrorLogger: size-capped file with a single .log.1 rotation,
  honours the @ operator, never throws.
- Admin: new "Debug Error Log" page (levels, size cap, auto-off, on-page
  viewer, clear, download) + debugLog action mod.
- Menu: admin-only quick on/off widget (TZ_DEBUG_ON/OFF, EN/FR/RO).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-12 17:18:39 +03:00

50 lines
1.9 KiB
Smarty

<?php
#################################################################################
## -= YOU MAY NOT REMOVE OR CHANGE THIS NOTICE =- ##
## --------------------------------------------------------------------------- ##
## Filename : debug_status.tpl ##
## Type : Left Menu Widget (admin only) ##
## --------------------------------------------------------------------------- ##
## Project : TravianZ ##
## Quick on/off toggle for the Debug Error Log, handy to flip while playing ##
## to reproduce a bug. Transparent to players; visible to admins only. ##
## --------------------------------------------------------------------------- ##
#################################################################################
global $database, $session;
if($isAdmin) {
// === QUICK TOGGLE from the menu (?dbg=on / ?dbg=off) ===
if(isset($_GET['dbg']) && ($_GET['dbg'] == 'on' || $_GET['dbg'] == 'off')) {
$newState = ($_GET['dbg'] == 'on') ? 1 : 0;
$database->setDebugMode($newState, $session->uid);
// redirect to clean the URL
$cleanUrl = strtok($_SERVER["REQUEST_URI"], '?');
header("Location: $cleanUrl");
exit;
}
$dbg = $database->getDebugMode();
if(!empty($dbg['active'])) {
$started = !empty($dbg['started_at']) ? date('H:i d.m.Y', $dbg['started_at']) : '-';
?>
<a href="?dbg=off"
title="Debug capture ON since <?=$started?> - Click to STOP"
style="color:#dc2626; font-weight:700;">
<?php echo TZ_DEBUG_ON; ?>
</a>
<?php
} else {
?>
<a href="?dbg=on"
title="Debug capture OFF - Click to START"
style="color:#16a34a; font-weight:700;">
<?php echo TZ_DEBUG_OFF; ?>
</a>
<?php
}
}
?>