- Add comprehensive health check system with multiple endpoints - Add Prometheus metrics endpoint - Add production logging configurations (5 strategies) - Add complete deployment documentation suite: * QUICKSTART.md - 30-minute deployment guide * DEPLOYMENT_CHECKLIST.md - Printable verification checklist * DEPLOYMENT_WORKFLOW.md - Complete deployment lifecycle * PRODUCTION_DEPLOYMENT.md - Comprehensive technical reference * production-logging.md - Logging configuration guide * ANSIBLE_DEPLOYMENT.md - Infrastructure as Code automation * README.md - Navigation hub * DEPLOYMENT_SUMMARY.md - Executive summary - Add deployment scripts and automation - Add DEPLOYMENT_PLAN.md - Concrete plan for immediate deployment - Update README with production-ready features All production infrastructure is now complete and ready for deployment.
68 lines
1.7 KiB
PHP
68 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Framework\Logging\Handlers;
|
|
|
|
use App\Framework\Logging\LogHandler;
|
|
use App\Framework\Logging\LogLevel;
|
|
use App\Framework\Logging\LogRecord;
|
|
|
|
final readonly class WebHandler implements LogHandler
|
|
{
|
|
public function __construct(
|
|
private LogLevel $minLevel = LogLevel::DEBUG,
|
|
private bool $debugOnly = true
|
|
) {
|
|
}
|
|
|
|
public function isHandling(LogRecord $record): bool
|
|
{
|
|
// Nur bei Web-Requests (nicht CLI)
|
|
if (PHP_SAPI === 'cli') {
|
|
return false;
|
|
}
|
|
|
|
// Debug-Modus-Check
|
|
if ($this->debugOnly && ! filter_var(getenv('APP_DEBUG'), FILTER_VALIDATE_BOOLEAN)) {
|
|
return false;
|
|
}
|
|
|
|
return $record->level->value >= $this->minLevel->value;
|
|
}
|
|
|
|
public function handle(LogRecord $record): void
|
|
{
|
|
$timestamp = $record->getFormattedTimestamp();
|
|
$level = $record->level->getName();
|
|
$message = $record->message;
|
|
$channel = $record->channel;
|
|
|
|
// Request-ID falls vorhanden
|
|
$requestId = $record->hasExtra('request_id')
|
|
? "[{$record->getExtra('request_id')}] "
|
|
: '';
|
|
|
|
// Channel falls vorhanden
|
|
$channelPrefix = $channel ? "[$channel] " : '';
|
|
|
|
$logLine = sprintf(
|
|
'[%s] %s[%s] %s%s',
|
|
$timestamp,
|
|
$requestId,
|
|
$level,
|
|
$channelPrefix,
|
|
$message
|
|
);
|
|
|
|
// Context-Daten, falls vorhanden
|
|
$context = $record->getContext();
|
|
if (! empty($context)) {
|
|
$logLine .= ' | Context: ' . json_encode($context, JSON_UNESCAPED_SLASHES);
|
|
}
|
|
|
|
// In error_log schreiben
|
|
error_log($logLine);
|
|
}
|
|
}
|