/** * Logs with an arbitrary level. * * @param mixed $level * @param string $message * @param array $context * @return null */ public function log($level, $message, array $context = array()) { if (!$this->isEnabled()) { return false; } $tags = array(); if (isset($context['_tags'])) { $tags = is_array($context['_tags']) ? $context['_tags'] : explode(',', trim((string) $context['_tags'])); unset($context['_tags']); } $timer = null; if (isset($context['_timer']) && $context['_timer'] instanceof Timer) { $timer = $context['_timer']; unset($context['_timer']); } $this->_log[] = array('message' => StringUtils::parseVariables((string) $message, $context), 'context' => $context, '_tags' => $tags, '_timestamp' => Timer::getMicroTime(), '_time' => new \DateTime(), '_level' => $level, '_timer' => $timer); }
public function testParseVariables() { $basicResult = 'lorem ipsum dolor sit amet'; $basicString = 'lorem {var1} dolor {var2}{undefined} amet'; $this->assertEmpty(StringUtils::parseVariables('', array())); $this->assertEquals('lorem ipsum dolor sit amet', StringUtils::parseVariables('lorem {var1} dolor {var2}{undefined} amet', array('var1' => 'ipsum', 'var2' => 'sit'))); $variables = new \stdClass(); $variables->var1 = 'ipsum'; $variables->var2 = 'sit'; $this->assertEquals($basicResult, StringUtils::parseVariables($basicString, $variables)); $variables = new ItemMagicClass(5, 'Lipsum', 1, '2013.07.26'); $this->assertEquals('Item #5 - "Lipsum", cat: 1 on 2013.07.26', StringUtils::parseVariables('Item #{id} - "{name}", cat: {categoryId} on {date}', $variables)); $variables = new ItemClass(5, 'Lipsum', 1, '2013.07.26'); $this->assertEquals('Item #5 - "Lipsum", cat: 1 on 2013.07.26', StringUtils::parseVariables('Item #{id} - "{name}", cat: {categoryId} on {date}', $variables)); }