diff options
author | Hennadiy Verkh <h.verkh@traveltrex.com> | 2014-03-24 10:51:45 +0100 |
---|---|---|
committer | Hennadiy Verkh <h.verkh@traveltrex.com> | 2014-03-24 10:51:45 +0100 |
commit | 36f3d0e52f48777cdd2618d71749c923e1a4e530 (patch) | |
tree | 3d4a634e331917215b96ee6a61c6ca648b8462b8 /src/Monolog/Processor/MemoryProcessor.php | |
parent | 392ef35fd470638e08d0160d6b1cbab63cb23174 (diff) | |
download | monolog-36f3d0e52f48777cdd2618d71749c923e1a4e530.zip monolog-36f3d0e52f48777cdd2618d71749c923e1a4e530.tar.gz monolog-36f3d0e52f48777cdd2618d71749c923e1a4e530.tar.bz2 |
Added configuration option to MemoryProcessors with a possibility to disable formatting.
Diffstat (limited to 'src/Monolog/Processor/MemoryProcessor.php')
-rw-r--r-- | src/Monolog/Processor/MemoryProcessor.php | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/Monolog/Processor/MemoryProcessor.php b/src/Monolog/Processor/MemoryProcessor.php index 7551043..9058b57 100644 --- a/src/Monolog/Processor/MemoryProcessor.php +++ b/src/Monolog/Processor/MemoryProcessor.php @@ -18,26 +18,38 @@ namespace Monolog\Processor; */ abstract class MemoryProcessor { + /** + * @var boolean Set this to true to get the real size of memory allocated from system. + * If not set or false only the memory used by emalloc() is reported. + */ protected $realUsage; + protected $useFormatting; + /** - * @param boolean $realUsage + * @param boolean $realUsage Set this to true to get the real size of memory allocated from system. + * @param bool $useFormatting If true, then format memory size to human readable string (MB, KB, B depending on size) */ - public function __construct($realUsage = true) + public function __construct($realUsage = true, $useFormatting = true) { $this->realUsage = (boolean) $realUsage; + $this->useFormatting = (boolean) $useFormatting; } /** - * Formats bytes into a human readable string + * Formats bytes into a human readable string (if $this->useFormatting is true) * * @param int $bytes - * @return string + * @return string|int */ - protected static function formatBytes($bytes) + protected function formatBytes($bytes) { $bytes = (int) $bytes; + if (!$this->useFormatting) { + return $bytes; + } + if ($bytes > 1024*1024) { return round($bytes/1024/1024, 2).' MB'; } elseif ($bytes > 1024) { |