MemoryProcessor.php 1007 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. * Some methods that are common for all memory processors
  13. *
  14. * @author Rob Jensen
  15. */
  16. abstract class MemoryProcessor
  17. {
  18. protected $realUsage;
  19. /**
  20. * @param boolean $realUsage
  21. */
  22. public function __construct($realUsage = true)
  23. {
  24. $this->realUsage = (boolean) $realUsage;
  25. }
  26. /**
  27. * Formats bytes into a human readable string
  28. *
  29. * @param int $bytes
  30. * @return string
  31. */
  32. protected static function formatBytes($bytes)
  33. {
  34. $bytes = (int) $bytes;
  35. if ($bytes > 1024*1024) {
  36. return round($bytes/1024/1024, 2).' MB';
  37. } elseif ($bytes > 1024) {
  38. return round($bytes/1024, 2).' KB';
  39. }
  40. return $bytes . ' B';
  41. }
  42. }