mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 16:19:19 +02:00
- Add monolog/monolog dependency (^3.10)
- Create app/Logger.php central factory with channels: app, admin, error, audit
- Each channel gets RotatingFileHandler (30-day retention) with pass-through LineFormatter
preserving existing JSON format contracts
- Rewrite AppLogger as thin facade delegating to Logger::get('app')
- Rewrite ErrorHandler::log() to delegate to Logger::get('error')
- Rewrite AdminLogger file output to delegate to Logger::get('admin'), keep DB writes
- Add Monolog file shadow to Audit via Logger::get('audit') (Option A per monolog-plan)
- Log level controlled by LOG_LEVEL env var (defaults: DEBUG in cli-server, WARNING otherwise)
- Graceful NullHandler fallback when log directory is not writable
- Update SystemController LOG_FILES: remove php_error, add app/admin/error/audit
- JSON app logs parsed to readable one-liners in the log viewer
- Remove nginx config tab (parametres + fragment + template + css)
- Friendly empty-state message when app log files don't exist yet (notYet)
- PHP tail fallback when exec() unavailable
- All 228 PHPUnit tests pass, no call sites changed
170 lines
6.1 KiB
PHP
170 lines
6.1 KiB
PHP
<?php
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* SystemControllerHelpersTest — Pure logic tests for the static helper methods
|
|
* in SystemController (humanBytes, diskColor, logLineClass,
|
|
* statusLabel, statusClass).
|
|
*
|
|
* These are stateless, no-IO functions.
|
|
*/
|
|
class SystemControllerHelpersTest extends TestCase
|
|
{
|
|
// ── humanBytes() ──────────────────────────────────────────────────────────
|
|
|
|
public function testHumanBytesZero(): void
|
|
{
|
|
$this->assertSame('0.0 KB', SystemController::humanBytes(0));
|
|
}
|
|
|
|
public function testHumanBytesBelowOneKB(): void
|
|
{
|
|
$this->assertSame('1.0 KB', SystemController::humanBytes(1023));
|
|
}
|
|
|
|
public function testHumanBytesOneKB(): void
|
|
{
|
|
$this->assertSame('1.0 KB', SystemController::humanBytes(1024));
|
|
}
|
|
|
|
public function testHumanBytesOneMB(): void
|
|
{
|
|
// threshold is > 1048576, so exactly 1048576 is still KB
|
|
$this->assertSame('1,024.0 KB', SystemController::humanBytes(1048576));
|
|
}
|
|
|
|
public function testHumanBytesOneGB(): void
|
|
{
|
|
// threshold is > 1073741824, so exactly that is still MB
|
|
$this->assertSame('1,024.0 MB', SystemController::humanBytes(1073741824));
|
|
}
|
|
|
|
public function testHumanBytes1523MB(): void
|
|
{
|
|
$bytes = (int)(1.5 * 1048576);
|
|
$this->assertSame('1.5 MB', SystemController::humanBytes($bytes));
|
|
}
|
|
|
|
public function testHumanBytes2500GB(): void
|
|
{
|
|
$bytes = (int)(2.5 * 1073741824);
|
|
$this->assertSame('2.5 GB', SystemController::humanBytes($bytes));
|
|
}
|
|
|
|
// ── diskColor() ───────────────────────────────────────────────────────────
|
|
|
|
public function testDiskColorBelowWarning(): void
|
|
{
|
|
$this->assertSame('#4caf50', SystemController::diskColor(0));
|
|
$this->assertSame('#4caf50', SystemController::diskColor(50));
|
|
$this->assertSame('#4caf50', SystemController::diskColor(70));
|
|
}
|
|
|
|
public function testDiskColorWarning(): void
|
|
{
|
|
$this->assertSame('#ffc107', SystemController::diskColor(71));
|
|
$this->assertSame('#ffc107', SystemController::diskColor(85));
|
|
}
|
|
|
|
public function testDiskColorCritical(): void
|
|
{
|
|
$this->assertSame('#e05555', SystemController::diskColor(86));
|
|
$this->assertSame('#e05555', SystemController::diskColor(99));
|
|
$this->assertSame('#e05555', SystemController::diskColor(100));
|
|
}
|
|
|
|
// ── logLineClass() ────────────────────────────────────────────────────────
|
|
|
|
public function testLogLineClassCrit(): void
|
|
{
|
|
$this->assertSame('log-crit', SystemController::logLineClass('[crit] Fatal'));
|
|
$this->assertSame('log-crit', SystemController::logLineClass('[emerg] Emergency'));
|
|
$this->assertSame('log-crit', SystemController::logLineClass('[alert] Alert'));
|
|
}
|
|
|
|
public function testLogLineClassError(): void
|
|
{
|
|
$this->assertSame('log-error', SystemController::logLineClass('[error] An error'));
|
|
}
|
|
|
|
public function testLogLineClassWarn(): void
|
|
{
|
|
$this->assertSame('log-warn', SystemController::logLineClass('[warn] Warning'));
|
|
}
|
|
|
|
public function testLogLineClassNotice(): void
|
|
{
|
|
$this->assertSame('log-notice', SystemController::logLineClass('[notice] Notice'));
|
|
}
|
|
|
|
public function testLogLineClassHttp500(): void
|
|
{
|
|
// Matches " 500 " pattern in nginx-style log
|
|
$this->assertSame('log-error', SystemController::logLineClass('GET / " 500 123 "'));
|
|
$this->assertSame('log-error', SystemController::logLineClass('GET / " 404 123 "'));
|
|
}
|
|
|
|
public function testLogLineClassHttp300(): void
|
|
{
|
|
$this->assertSame('log-notice', SystemController::logLineClass('GET / " 302 456 "'));
|
|
}
|
|
|
|
public function testLogLineClassDefault(): void
|
|
{
|
|
$this->assertSame('', SystemController::logLineClass('Just a plain log message'));
|
|
$this->assertSame('', SystemController::logLineClass('GET / " 200 123 "'));
|
|
}
|
|
|
|
// ── statusLabel() ─────────────────────────────────────────────────────────
|
|
|
|
public function testStatusLabelActive(): void
|
|
{
|
|
$this->assertSame('● En ligne', SystemController::statusLabel('active'));
|
|
}
|
|
|
|
public function testStatusLabelInactive(): void
|
|
{
|
|
$this->assertSame('○ Inactif', SystemController::statusLabel('inactive'));
|
|
}
|
|
|
|
public function testStatusLabelFailed(): void
|
|
{
|
|
$this->assertSame('✕ Erreur', SystemController::statusLabel('failed'));
|
|
}
|
|
|
|
public function testStatusLabelWarn(): void
|
|
{
|
|
$this->assertSame('⚠ Attention', SystemController::statusLabel('warn'));
|
|
}
|
|
|
|
public function testStatusLabelUnknown(): void
|
|
{
|
|
$this->assertSame('? Inconnu', SystemController::statusLabel('unknown'));
|
|
$this->assertSame('? Inconnu', SystemController::statusLabel('bogus'));
|
|
}
|
|
|
|
// ── statusClass() ─────────────────────────────────────────────────────────
|
|
|
|
public function testStatusClassOk(): void
|
|
{
|
|
$this->assertSame('status-ok', SystemController::statusClass('active'));
|
|
}
|
|
|
|
public function testStatusClassWarn(): void
|
|
{
|
|
$this->assertSame('status-warn', SystemController::statusClass('inactive'));
|
|
$this->assertSame('status-warn', SystemController::statusClass('warn'));
|
|
}
|
|
|
|
public function testStatusClassError(): void
|
|
{
|
|
$this->assertSame('status-err', SystemController::statusClass('failed'));
|
|
}
|
|
|
|
public function testStatusClassUnknown(): void
|
|
{
|
|
$this->assertSame('status-unknown', SystemController::statusClass('bogus'));
|
|
}
|
|
}
|