MemoryUsageProcessor.php 874 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  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. /**
  20. * @param array $record
  21. * @return array
  22. */
  23. public function __invoke(array $record)
  24. {
  25. $bytes = memory_get_usage($this->realUsage);
  26. $formatted = self::formatBytes($bytes);
  27. $record['extra'] = array_merge(
  28. $record['extra'],
  29. array(
  30. 'memory_usage' => $formatted,
  31. )
  32. );
  33. return $record;
  34. }
  35. }