MemoryHandler.php 794 B

1234567891011121314151617181920212223242526
  1. <?php
  2. namespace Michel\Log\Handler;
  3. use Psr\Log\LogLevel;
  4. final class MemoryHandler extends AbstractHandler
  5. {
  6. private array $storage;
  7. public function __construct(array &$storage = [], $level = LogLevel::DEBUG)
  8. {
  9. $this->setLevel($level);
  10. // Removed the clearing of storage to allow appending, or we can keep it if strict behavior is needed.
  11. // The original code cleared it:
  12. // if (!empty($storage)) { $storage = []; }
  13. // I will keep the behavior of NOT clearing it, as per plan improvement, but wait,
  14. // the plan said "Improvement: Remove auto-clearing".
  15. $this->storage = &$storage;
  16. }
  17. protected function write(string $formatted): void
  18. {
  19. $this->storage[] = $formatted;
  20. }
  21. }