Skip to content

Commit

Permalink
Merge pull request #2 from jacobemerick/feature/raw-memory-logging
Browse files Browse the repository at this point in the history
Feature/raw memory logging
  • Loading branch information
jacobemerick committed Jan 27, 2016
2 parents 4eb90d6 + 3df3f0c commit 8545046
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Console.php
Expand Up @@ -38,14 +38,17 @@ public function log($data)
*
* @param mixed $object
* @param string $name
* @param boolean $literal
*/
public function logMemory($object = null, $name = 'PHP')
public function logMemory($object = null, $name = 'PHP', $literal = false)
{
$memory = memory_get_usage();
$dataType = '';
if (!is_null($object)) {
if (!is_null($object) && !$literal) {
$memory = strlen(serialize($object));
$dataType = gettype($object);
} else if (is_numeric($object) && $literal) {
$memory = floatval($object);
}

array_push($this->store, array(
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/ConsoleTest.php
Expand Up @@ -41,6 +41,15 @@ public function testLogMemory()
$this->assertEquals($memory, $log['data']);
$this->assertEquals('array', $log['data_type']);
$this->assertEquals('memory', $log['type']);

$data = '12345';

$console = new Console();
$console->logMemory($data, 'PHP', true);
$store = $this->getProtectedStore($console);
$log = array_pop($store);

$this->assertEquals($data, $log['data']);
}

public function testLogError()
Expand Down

0 comments on commit 8545046

Please sign in to comment.