113 lines
4.0 KiB
PHP
Executable File
113 lines
4.0 KiB
PHP
Executable File
<?php
|
|
if (!defined('BASE_PATH')) {
|
|
define('BASE_PATH', dirname(__DIR__, 2));
|
|
}
|
|
$config = require_once BASE_PATH . '/config/config.php';
|
|
require_once BASE_PATH . '/src/Auth.php';
|
|
require_once BASE_PATH . '/src/Database.php';
|
|
|
|
$auth = new Auth();
|
|
$auth->requireAdmin();
|
|
|
|
$logFile = BASE_PATH . '/public/logs/error.log';
|
|
|
|
$logs = [];
|
|
if (file_exists($logFile)) {
|
|
$logs = array_reverse(file($logFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES));
|
|
$logs = array_slice($logs, 0, 100);
|
|
}
|
|
|
|
$currentPage = 'logs';
|
|
$pageTitle = 'Logs del Sistema';
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="es">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Logs - Contenedor Ibiza</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<style>
|
|
.log-entry {
|
|
font-family: monospace;
|
|
font-size: 12px;
|
|
padding: 4px 8px;
|
|
border-bottom: 1px solid #eee;
|
|
}
|
|
.log-entry:hover {
|
|
background-color: #f8f9fa;
|
|
}
|
|
.log-error { color: #dc3545; }
|
|
.log-warning { color: #ffc107; }
|
|
.log-notice { color: #0dcaf0; }
|
|
.log-info { color: #6c757d; }
|
|
.log-container {
|
|
max-height: 70vh;
|
|
overflow-y: auto;
|
|
background: #1e1e1e;
|
|
color: #d4d4d4;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<?php include BASE_PATH . '/public/partials/navbar.php'; ?>
|
|
|
|
<div class="container mt-4">
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h2>Logs del Sistema</h2>
|
|
<div>
|
|
<a href="?clear=1" class="btn btn-outline-danger btn-sm" onclick="return confirm('¿Vaciar todos los logs?')">Vaciar Logs</a>
|
|
<a href="<?= rtrim($config['site_url'] ?? '', '/') ?>/logs/error.log" target="_blank" class="btn btn-outline-secondary btn-sm">Ver Archivo Completo</a>
|
|
</div>
|
|
</div>
|
|
|
|
<?php
|
|
if (isset($_GET['clear']) && $_GET['clear'] == '1') {
|
|
file_put_contents($logFile, '');
|
|
header('Location: logs.php');
|
|
exit;
|
|
}
|
|
?>
|
|
|
|
<div class="card shadow-sm">
|
|
<div class="card-body p-0">
|
|
<div class="log-container">
|
|
<?php if (empty($logs)): ?>
|
|
<div class="p-3 text-muted">No hay logs registrados.</div>
|
|
<?php else: ?>
|
|
<?php foreach ($logs as $log): ?>
|
|
<?php
|
|
$class = 'log-info';
|
|
if (stripos($log, 'ERROR') !== false || stripos($log, 'FATAL') !== false) {
|
|
$class = 'log-error';
|
|
} elseif (stripos($log, 'WARNING') !== false) {
|
|
$class = 'log-warning';
|
|
} elseif (stripos($log, 'NOTICE') !== false) {
|
|
$class = 'log-notice';
|
|
}
|
|
?>
|
|
<div class="log-entry <?= $class ?>"><?= htmlspecialchars($log) ?></div>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card mt-4 shadow-sm">
|
|
<div class="card-header bg-secondary text-white">
|
|
<h5 class="mb-0">Información</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<ul class="mb-0">
|
|
<li>Los errores se guardan automáticamente en: <code>logs/error.log</code></li>
|
|
<li>Se registran errores de PHP, excepciones y errores fatales.</li>
|
|
<li>La configuración está en: <code>config/error_logging.php</code></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|