/** * Logs with an arbitrary level. * * @param mixed $level * @param string $message * @param array $context * @return null */ public function log($level, $message, array $context = array()) { // add color to all injected variables $message = preg_replace_callback('/{([\\w\\d_\\.]+)}/is', function ($matches) { $var = $matches[1]; return '<info>{' . $var . '}</info>'; }, $message); $message = StringUtils::interpolate($message, $context); $alert = ''; switch ($level) { case LogLevel::ALERT: case LogLevel::CRITICAL: case LogLevel::EMERGENCY: case LogLevel::ERROR: $alert = '<error> ' . $level . ' </error> '; break; case LogLevel::NOTICE: case LogLevel::WARNING: $alert = '<fg=yellow;options=bold>' . $level . '</fg=yellow;options=bold> '; break; } $this->output->writeln($alert . $message . ' [@mem: ' . StringUtils::bytesToString(Timer::getCurrentMemory()) . ']'); }
public function testGetCurrentMemory() { $current = memory_get_usage(true); $fromTimer = Timer::getCurrentMemory(); $this->assertInternalType('int', $fromTimer); // make sure diff isn't bigger than 8kb // because memory actually can be different when timer reads it // and when the test reads it $diff = abs($current - $fromTimer); $this->assertLessThanOrEqual(1024 * 8, $diff); }