1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-08 14:16:42 +02:00

Adjustments to the Memory processors

This commit is contained in:
Jordi Boggiano
2011-07-19 23:30:31 +02:00
parent 7788c0cee9
commit f9f27ce43f
3 changed files with 11 additions and 17 deletions

View File

@@ -11,17 +11,14 @@
namespace Monolog\Processor; namespace Monolog\Processor;
use Monolog\Processor\MemoryProcessor;
/** /**
* Injects memory_get_peak_usage in all records * Injects memory_get_peak_usage in all records
* *
* @see Monolog\Processor\MemoryProcessor__construct() for options * @see Monolog\Processor\MemoryProcessor::__construct() for options
* @author Rob Jensen * @author Rob Jensen
*/ */
class MemoryPeakUsageProcessor extends MemoryProcessor class MemoryPeakUsageProcessor extends MemoryProcessor
{ {
/** /**
* @param array $record * @param array $record
* @return array * @return array
@@ -29,7 +26,7 @@ class MemoryPeakUsageProcessor extends MemoryProcessor
public function __invoke(array $record) public function __invoke(array $record)
{ {
$bytes = memory_get_peak_usage($this->realUsage); $bytes = memory_get_peak_usage($this->realUsage);
$formatted = MemoryProcessor::formatBytes($bytes); $formatted = self::formatBytes($bytes);
$record['extra'] = array_merge( $record['extra'] = array_merge(
$record['extra'], $record['extra'],

View File

@@ -13,11 +13,11 @@ namespace Monolog\Processor;
/** /**
* Some methods that are common for all memory processors * Some methods that are common for all memory processors
*
* @author Rob Jensen * @author Rob Jensen
*/ */
class MemoryProcessor class MemoryProcessor
{ {
protected $realUsage; protected $realUsage;
/** /**
@@ -34,18 +34,17 @@ class MemoryProcessor
* @param int $bytes * @param int $bytes
* @return string * @return string
*/ */
public static function formatBytes($bytes) protected static function formatBytes($bytes)
{ {
$bytes = (int) $bytes; $bytes = (int) $bytes;
if ($bytes > 1024*1024) { if ($bytes > 1024*1024) {
$bytes = round($bytes/1024/1024, 2).' MB'; return round($bytes/1024/1024, 2).' MB';
} elseif ($bytes > 1024) { } elseif ($bytes > 1024) {
$bytes = round($bytes/1024, 2).' KB'; return round($bytes/1024, 2).' KB';
} else {
$bytes .= ' B';
} }
return $bytes; return $bytes . ' B';
} }
} }

View File

@@ -11,16 +11,14 @@
namespace Monolog\Processor; namespace Monolog\Processor;
use Monolog\Processor\MemoryProcessor;
/** /**
* Injects memory_get_usage in all records * Injects memory_get_usage in all records
* @see Monolog\Processor\MemoryProcessor__construct() for options *
* @see Monolog\Processor\MemoryProcessor::__construct() for options
* @author Rob Jensen * @author Rob Jensen
*/ */
class MemoryUsageProcessor extends MemoryProcessor class MemoryUsageProcessor extends MemoryProcessor
{ {
/** /**
* @param array $record * @param array $record
* @return array * @return array
@@ -28,7 +26,7 @@ class MemoryUsageProcessor extends MemoryProcessor
public function __invoke(array $record) public function __invoke(array $record)
{ {
$bytes = memory_get_usage($this->realUsage); $bytes = memory_get_usage($this->realUsage);
$formatted = MemoryProcessor::formatBytes($bytes); $formatted = self::formatBytes($bytes);
$record['extra'] = array_merge( $record['extra'] = array_merge(
$record['extra'], $record['extra'],