| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
* This file is part of the Monolog package. |
| 5 |
* |
| 6 |
* (c) Jordi Boggiano <j.boggiano@seld.be> |
| 7 |
* |
| 8 |
* For the full copyright and license information, please view the LICENSE |
| 9 |
* file that was distributed with this source code. |
| 10 |
*/ |
| 11 |
|
| 12 |
/** |
| 13 |
* Some methods that are common for all memory processors |
| 14 |
* |
| 15 |
* @author Rob Jensen |
| 16 |
*/ |
| 17 |
abstract class Monolog_Processor_MemoryProcessor implements Monolog_Processor_ProcessorInterface |
| 18 |
{ |
| 19 |
protected $realUsage; |
| 20 |
|
| 21 |
/** |
| 22 |
* @param boolean $realUsage |
| 23 |
*/ |
| 24 |
public function __construct($realUsage = true) |
| 25 |
{ |
| 26 |
$this->realUsage = (boolean) $realUsage; |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Formats bytes into a human readable string |
| 31 |
* |
| 32 |
* @param int $bytes |
| 33 |
* |
| 34 |
* @return string |
| 35 |
*/ |
| 36 |
protected static function formatBytes($bytes) |
| 37 |
{ |
| 38 |
$bytes = (int) $bytes; |
| 39 |
|
| 40 |
if ($bytes > 1024 * 1024) { |
| 41 |
return round($bytes / 1024 / 1024, 2).' MB'; |
| 42 |
} elseif ($bytes > 1024) { |
| 43 |
return round($bytes / 1024, 2).' KB'; |
| 44 |
} |
| 45 |
|
| 46 |
return $bytes.' B'; |
| 47 |
} |
| 48 |
} |
| 49 |
|