Esempio n. 1
0
 /**
  * @test
  * @depends constsTest
  */
 public function toLevelTest()
 {
     $this->assertEquals(Level::toLevel('CriTIcal'), Level::CRITICAL);
     $this->assertEquals(Level::toLevel('error'), Level::ERROR);
     $this->assertEquals(Level::toLevel('asdgfasd'), 0);
     $this->assertEquals(Level::toLevel(8), 8);
     $this->assertEquals(Level::toLevel(12.6), 12);
     $this->assertEquals(Level::toLevel('12'), 12);
 }
Esempio n. 2
0
 /**
  * 
  * @param int|string $level Handled level
  */
 public function __construct($level = 0)
 {
     $this->level = Level::toLevel($level);
 }
Esempio n. 3
0
 /**
  * 
  * @param int|string $level
  * @param string $message
  * @param array $context
  * @return self
  */
 public function log($level, $message, array $context = array())
 {
     // Converting Psr\LogLevel to int
     $level = Level::toLevel($level);
     // Level is unknown? Stop
     if (!Level::is($level)) {
         $this->emit('unknown', $level, $message);
         return $this;
     }
     // If $level is a mask, explode it!
     if (!BitMask::isSingleFlag($level)) {
         $me = __FUNCTION__;
         foreach (BitMask::maskToFlags($level) as $flag) {
             $this->{$me}($flag, $message, $context);
         }
         return $this;
     } else {
         if (!$this->handler->isHandled($level)) {
             $this->emit('unhandled', $level, $message);
             return $this;
         }
     }
     // Make log struct
     $log = ['level' => $level, 'name' => Level::getLevelName($level), 'message' => $message, 'context' => $context, 'timestamp' => \microtime(true), 'extra' => []];
     // Iterate the filters
     foreach ($this->filters as &$filter) {
         $log = $filter($log);
     }
     $this->emit('log', $log);
     $this->emit(\strtolower($log['name']), $log);
     // Call handler
     $this->handler->handle($log);
     return $this;
 }