1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-11 15:44:34 +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

@@ -28,8 +28,8 @@ 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 = MemoryProcessor::formatBytes($bytes);
$record['extra'] = array_merge( $record['extra'] = array_merge(
$record['extra'], $record['extra'],

View File

@@ -15,21 +15,17 @@ 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
*/ */
abstract class MemoryProcessor extends AbstractProcessor class MemoryProcessor
{ {
protected $realUsage; 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) $realUsage;
$this->realUsage = (boolean) $options['realUsage'];
} else {
$this->realUsage = true;
}
} }
/** /**
@@ -38,12 +34,12 @@ abstract class MemoryProcessor extends AbstractProcessor
* @param int $bytes * @param int $bytes
* @return string * @return string
*/ */
public static function formatBytes( $bytes ) public 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'; $bytes = round($bytes/1024/1024, 2).' MB';
} else if ($bytes > 1024) { } elseif ($bytes > 1024) {
$bytes = round($bytes/1024, 2).' KB'; $bytes = round($bytes/1024, 2).' KB';
} else { } else {
$bytes .= ' B'; $bytes .= ' B';

View File

@@ -27,8 +27,8 @@ 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 = MemoryProcessor::formatBytes($bytes);
$record['extra'] = array_merge( $record['extra'] = array_merge(
$record['extra'], $record['extra'],