ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
MemoryProcessor.php
Go to the documentation of this file.
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 
19 abstract class MemoryProcessor implements ProcessorInterface
20 {
24  protected $realUsage;
25 
29  protected $useFormatting;
30 
35  public function __construct($realUsage = true, $useFormatting = true)
36  {
37  $this->realUsage = (bool) $realUsage;
38  $this->useFormatting = (bool) $useFormatting;
39  }
40 
47  protected function formatBytes($bytes)
48  {
49  $bytes = (int) $bytes;
50 
51  if (!$this->useFormatting) {
52  return $bytes;
53  }
54 
55  if ($bytes > 1024 * 1024) {
56  return round($bytes / 1024 / 1024, 2).' MB';
57  } elseif ($bytes > 1024) {
58  return round($bytes / 1024, 2).' KB';
59  }
60 
61  return $bytes . ' B';
62  }
63 }
formatBytes($bytes)
Formats bytes into a human readable string if $this->useFormatting is true, otherwise return $bytes a...
__construct($realUsage=true, $useFormatting=true)
Some methods that are common for all memory processors.
An optional interface to allow labelling Monolog processors.