Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
0
 /**
  * Attach a logger handler on the end of list.
  * 
  * @param HandlerInterface $handler
  * @return self
  */
 public function pushHandler(HandlerInterface $handler)
 {
     $this->handlers[] = $handler;
     $this->level = BitMask::addFlag($this->level, $handler->getHandledLevel());
     return $this;
 }