MemoryUsageProcessor.php 780 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php declare(strict_types=1);
  2. /*
  3. * This file is part of the Monolog package.
  4. *
  5. * (c) Jordi Boggiano <j.boggiano@seld.be>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Monolog\Processor;
  11. /**
  12. * Injects memory_get_usage in all records
  13. *
  14. * @see Monolog\Processor\MemoryProcessor::__construct() for options
  15. * @author Rob Jensen
  16. */
  17. class MemoryUsageProcessor extends MemoryProcessor
  18. {
  19. public function __invoke(array $record): array
  20. {
  21. $usage = memory_get_usage($this->realUsage);
  22. if ($this->useFormatting) {
  23. $usage = $this->formatBytes($usage);
  24. }
  25. $record['extra']['memory_usage'] = $usage;
  26. return $record;
  27. }
  28. }