- Move 12 markdown files from root to docs/ subdirectories - Organize documentation by category: • docs/troubleshooting/ (1 file) - Technical troubleshooting guides • docs/deployment/ (4 files) - Deployment and security documentation • docs/guides/ (3 files) - Feature-specific guides • docs/planning/ (4 files) - Planning and improvement proposals Root directory cleanup: - Reduced from 16 to 4 markdown files in root - Only essential project files remain: • CLAUDE.md (AI instructions) • README.md (Main project readme) • CLEANUP_PLAN.md (Current cleanup plan) • SRC_STRUCTURE_IMPROVEMENTS.md (Structure improvements) This improves: ✅ Documentation discoverability ✅ Logical organization by purpose ✅ Clean root directory ✅ Better maintainability
98 lines
3.4 KiB
PHP
98 lines
3.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Framework\Logging;
|
|
|
|
use App\Framework\Config\TypedConfiguration;
|
|
use App\Framework\Core\PathProvider;
|
|
use App\Framework\DI\Container;
|
|
use App\Framework\DI\Initializer;
|
|
use App\Framework\Logging\Handlers\ConsoleHandler;
|
|
use App\Framework\Logging\Handlers\FileHandler;
|
|
use App\Framework\Logging\Handlers\MultiFileHandler;
|
|
use App\Framework\Logging\Handlers\QueuedLogHandler;
|
|
use App\Framework\Logging\Handlers\WebHandler;
|
|
use App\Framework\Queue\FileQueue;
|
|
use App\Framework\Queue\Queue;
|
|
use App\Framework\Queue\RedisQueue;
|
|
use App\Framework\Redis\RedisConfig;
|
|
use App\Framework\Redis\RedisConnection;
|
|
|
|
final readonly class LoggerInitializer
|
|
{
|
|
#[Initializer]
|
|
public function __invoke(TypedConfiguration $config, PathProvider $pathProvider, Container $container): Logger
|
|
{
|
|
// LogContextManager als Singleton im Container registrieren
|
|
if (! $container->has(LogContextManager::class)) {
|
|
$contextManager = new LogContextManager();
|
|
$container->singleton(LogContextManager::class, $contextManager);
|
|
|
|
// Globalen Kontext mit App-Informationen initialisieren
|
|
$contextManager->addGlobalData('app_version', $config->app->version);
|
|
$contextManager->addGlobalData('environment', $config->app->environment->value);
|
|
$contextManager->addGlobalTags('application', 'framework');
|
|
}
|
|
$processorManager = new ProcessorManager();
|
|
|
|
// Set log level based on environment
|
|
$minLevel = $config->app->isDebugEnabled()
|
|
? LogLevel::DEBUG
|
|
: LogLevel::INFO;
|
|
|
|
// Erstelle LogConfig für zentrale Pfadverwaltung
|
|
$logConfig = new LogConfig($pathProvider);
|
|
|
|
// Stelle sicher, dass alle Logverzeichnisse existieren
|
|
$logConfig->ensureLogDirectoriesExist();
|
|
|
|
$redisConfig = new RedisConfig(host: 'redis', database: 2);
|
|
$redisConnection = new RedisConnection($redisConfig, 'queue');
|
|
$queue = new RedisQueue($redisConnection, 'commands');
|
|
|
|
// Alternativ: FileQueue mit aufgelöstem Pfad
|
|
// $queuePath = $pathProvider->resolvePath('storage/queue');
|
|
// $queue = new FileQueue($queuePath);
|
|
|
|
// In production, we might want to exclude console handler
|
|
$handlers = [];
|
|
|
|
if (! $config->app->isProduction()) {
|
|
$handlers[] = new ConsoleHandler();
|
|
}
|
|
|
|
$handlers[] = new QueuedLogHandler($queue);
|
|
$handlers[] = new WebHandler();
|
|
|
|
// MultiFileHandler für automatisches Channel-Routing
|
|
$handlers[] = new MultiFileHandler(
|
|
$logConfig,
|
|
$pathProvider,
|
|
$minLevel,
|
|
'[{timestamp}] [{level_name}] [{channel}] {message}',
|
|
0644
|
|
);
|
|
|
|
// Fallback FileHandler für Kompatibilität (nur für 'app' Channel ohne Channel-Info)
|
|
$handlers[] = new FileHandler(
|
|
$logConfig->getLogPath('app'),
|
|
$minLevel,
|
|
'[{timestamp}] [{level_name}] {request_id}{channel}{message}',
|
|
0644,
|
|
null,
|
|
$pathProvider
|
|
);
|
|
|
|
// LogContextManager aus Container holen
|
|
$contextManager = $container->get(LogContextManager::class);
|
|
|
|
return new DefaultLogger(
|
|
minLevel: $minLevel,
|
|
handlers: $handlers,
|
|
processorManager: $processorManager,
|
|
contextManager: $contextManager,
|
|
);
|
|
}
|
|
}
|