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