1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-02-24 06:52:34 +01: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;
use Monolog\Processor\MemoryProcessor;
/**
* 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
*/
class MemoryPeakUsageProcessor extends MemoryProcessor
{
/**
* @param array $record
* @return array
@ -29,7 +26,7 @@ class MemoryPeakUsageProcessor extends MemoryProcessor
public function __invoke(array $record)
{
$bytes = memory_get_peak_usage($this->realUsage);
$formatted = MemoryProcessor::formatBytes($bytes);
$formatted = self::formatBytes($bytes);
$record['extra'] = array_merge(
$record['extra'],

View File

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

View File

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