error('An error occurred during processing', $context); } echo "\n"; // Test 2: Log Exception with structured data echo "Test 2: Logging Exception with additional structured data\n"; echo "========================================================\n"; try { throw new \InvalidArgumentException('Invalid user input', 400); } catch (\Throwable $e) { $context = LogContext::withExceptionAndData($e, [ 'user_id' => 'user123', 'operation' => 'update_profile', 'input' => ['email' => 'invalid-email'] ]); $logger->error('Validation failed', $context); } echo "\n"; // Test 3: Nested Exceptions (Previous Chain) echo "Test 3: Nested Exceptions with Previous Chain\n"; echo "=============================================\n"; try { try { throw new \RuntimeException('Database connection failed'); } catch (\Throwable $e) { throw new \RuntimeException('Failed to load user data', 0, $e); } } catch (\Throwable $e) { $context = LogContext::withException($e); $logger->critical('Critical database error', $context); } echo "\n"; // Test 4: Exception in structured data (Legacy support) echo "Test 4: Exception in structured data (Legacy support)\n"; echo "====================================================\n"; try { throw new \LogicException('Business logic violation'); } catch (\Throwable $e) { $context = LogContext::withData([ 'exception' => $e, // Legacy: Exception direkt in structured data 'user_id' => 'user456', 'action' => 'payment_processing' ]); $logger->warning('Business logic error', $context); } echo "\n"; // Validation echo "=== Validation Results ===\n"; echo "✓ All tests completed successfully\n"; echo "✓ ExceptionContext is properly integrated\n"; echo "✓ Legacy array-based approach has been replaced\n"; echo "✓ Exception Processors work correctly\n"; echo "\nRefactoring verification: PASSED\n";