1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-09 22:56:41 +02:00
This commit is contained in:
Rob Jensen
2011-07-19 15:04:23 +01:00
parent c0cfb39d75
commit 6a2e2142d6
4 changed files with 11 additions and 38 deletions

View File

@@ -1,23 +0,0 @@
<?php
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Monolog\Processor;
/**
* Basic processor class
* @author Rob Jensen
*/
abstract class AbstractProcessor
{
abstract public function __invoke( array $record );
}

View File

@@ -15,7 +15,7 @@ use Monolog\Processor\MemoryProcessor;
/**
* Injects memory_get_peak_usage in all records
*
*
* @see Monolog\Processor\MemoryProcessor__construct() for options
* @author Rob Jensen
*/
@@ -28,8 +28,8 @@ class MemoryPeakUsageProcessor extends MemoryProcessor
*/
public function __invoke(array $record)
{
$bytes = memory_get_peak_usage( $this->realUsage );
$formatted = MemoryProcessor::formatBytes( $bytes );
$bytes = memory_get_peak_usage($this->realUsage);
$formatted = MemoryProcessor::formatBytes($bytes);
$record['extra'] = array_merge(
$record['extra'],

View File

@@ -15,21 +15,17 @@ namespace Monolog\Processor;
* Some methods that are common for all memory processors
* @author Rob Jensen
*/
abstract class MemoryProcessor extends AbstractProcessor
class MemoryProcessor
{
protected $realUsage;
/**
* @param array $options
* @param boolean $realUsage
*/
public function __construct( $options = array() )
public function __construct($realUsage = true)
{
if(array_key_exists('realUsage', $options )){
$this->realUsage = (boolean) $options['realUsage'];
} else {
$this->realUsage = true;
}
$this->realUsage = (boolean) $realUsage;
}
/**
@@ -38,12 +34,12 @@ abstract class MemoryProcessor extends AbstractProcessor
* @param int $bytes
* @return string
*/
public static function formatBytes( $bytes )
public static function formatBytes($bytes)
{
$bytes = (int) $bytes;
if ($bytes > 1024*1024) {
$bytes = round($bytes/1024/1024, 2).' MB';
} else if ($bytes > 1024) {
} elseif ($bytes > 1024) {
$bytes = round($bytes/1024, 2).' KB';
} else {
$bytes .= ' B';

View File

@@ -27,8 +27,8 @@ class MemoryUsageProcessor extends MemoryProcessor
*/
public function __invoke(array $record)
{
$bytes = memory_get_usage( $this->realUsage );
$formatted = MemoryProcessor::formatBytes( $bytes );
$bytes = memory_get_usage($this->realUsage);
$formatted = MemoryProcessor::formatBytes($bytes);
$record['extra'] = array_merge(
$record['extra'],