feat: CI/CD pipeline setup complete - Ansible playbooks updated, secrets configured, workflow ready
This commit is contained in:
100
src/Framework/Logging/Handlers/InMemoryHandler.php
Normal file
100
src/Framework/Logging/Handlers/InMemoryHandler.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Framework\Logging\Handlers;
|
||||
|
||||
use App\Framework\Logging\LogLevel;
|
||||
use App\Framework\Logging\ValueObjects\LogContext;
|
||||
use App\Framework\Logging\ValueObjects\LogEntry;
|
||||
|
||||
/**
|
||||
* In-memory log handler for testing
|
||||
*
|
||||
* Stores all log entries in memory for inspection and assertions in tests
|
||||
*/
|
||||
final class InMemoryHandler implements LogHandler
|
||||
{
|
||||
/** @var LogEntry[] */
|
||||
private array $entries = [];
|
||||
|
||||
public function handle(LogEntry $entry): void
|
||||
{
|
||||
$this->entries[] = $entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all logged entries
|
||||
*
|
||||
* @return LogEntry[]
|
||||
*/
|
||||
public function getEntries(): array
|
||||
{
|
||||
return $this->entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get entries by log level
|
||||
*
|
||||
* @return LogEntry[]
|
||||
*/
|
||||
public function getEntriesByLevel(LogLevel $level): array
|
||||
{
|
||||
return array_filter(
|
||||
$this->entries,
|
||||
fn(LogEntry $entry) => $entry->level === $level
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a message was logged
|
||||
*/
|
||||
public function hasMessage(string $message): bool
|
||||
{
|
||||
foreach ($this->entries as $entry) {
|
||||
if (str_contains($entry->message, $message)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a message was logged at specific level
|
||||
*/
|
||||
public function hasMessageAtLevel(string $message, LogLevel $level): bool
|
||||
{
|
||||
foreach ($this->getEntriesByLevel($level) as $entry) {
|
||||
if (str_contains($entry->message, $message)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get number of logged entries
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return count($this->entries);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get number of entries by level
|
||||
*/
|
||||
public function countByLevel(LogLevel $level): int
|
||||
{
|
||||
return count($this->getEntriesByLevel($level));
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all logged entries
|
||||
*/
|
||||
public function clear(): void
|
||||
{
|
||||
$this->entries = [];
|
||||
}
|
||||
}
|
||||
30
src/Framework/Logging/Handlers/NullHandler.php
Normal file
30
src/Framework/Logging/Handlers/NullHandler.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Framework\Logging\Handlers;
|
||||
|
||||
use App\Framework\Logging\LogHandler;
|
||||
use App\Framework\Logging\LogRecord;
|
||||
|
||||
/**
|
||||
* NullHandler discards all log entries without any output
|
||||
*
|
||||
* Use Cases:
|
||||
* - MCP Server mode (prevents log interference with JSON-RPC)
|
||||
* - Testing environments where logging should be suppressed
|
||||
* - Performance-critical paths where logging overhead is unacceptable
|
||||
*/
|
||||
final readonly class NullHandler implements LogHandler
|
||||
{
|
||||
public function isHandling(LogRecord $record): bool
|
||||
{
|
||||
// Accept all levels but discard them
|
||||
return true;
|
||||
}
|
||||
|
||||
public function handle(LogRecord $record): void
|
||||
{
|
||||
// Discard all log entries - no output
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user