Esempio n. 1
0
 /**
  * @param Event $event
  *
  * @return bool
  */
 public function receive(Event $event) : bool
 {
     if ($this->minimunLevel && array_search($event->getLevel(), self::LOGLEVEL) < $this->minimunLevel) {
         return false;
     }
     return $this->send($event);
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 protected function send(Event $event) : bool
 {
     $handler = VarDumper::setHandler();
     dump($event->format());
     VarDumper::setHandler($handler);
     return true;
 }
Esempio n. 3
0
 /**
  * Logs with an arbitrary level.
  *
  * @param string $level
  * @param string $message
  * @param array $context
  *
  * @return null
  */
 public function log($level, $message, array $context = [])
 {
     if (isset($context['name'])) {
         $name = $context['name'];
         unset($context['name']);
     } else {
         $name = 'log.' . $level;
     }
     $event = new Event($name);
     $event->setLevel($level)->setMessage($message)->setContext($context);
     self::emit($event);
 }
Esempio n. 4
0
 /**
  * {@inheritdoc}
  */
 protected function send(Event $event) : bool
 {
     if (!is_resource($this->resource)) {
         $this->resource = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
     }
     $message = $event->format(false);
     $udpMessage = '<' . ($this->facility + $this->convertType($event->getLevel())) . '>' . $event->getDate()->format('M d H:i:s') . ' ' . ($this->hostname ? $this->hostname . ' ' : '') . $this->name . ($this->pid ? '[' . $this->pid . ']' : '') . ': ' . $message . "";
     if (strlen($udpMessage) > self::DATAGRAM_MAX_LENGTH) {
         $udpMessage = substr($udpMessage, 0, self::DATAGRAM_MAX_LENGTH);
     }
     $length = strlen($udpMessage);
     $size = socket_sendto($this->resource, $udpMessage, $length, $flags = 0, $this->ip, $this->port);
     return $size == $length;
 }
Esempio n. 5
0
 /**
  * @param \Cawa\Log\Event $event
  */
 public function onLogEvent(Event $event)
 {
     $message = $event->getMessage();
     if ($event->getContext()) {
         $isAssociative = array_keys($event->getContext()) !== range(0, count($event->getContext()) - 1);
         if ($isAssociative) {
             $message .= ' [' . implode('] [', array_map(function ($v, $k) {
                 return sprintf('%s: %s', ucfirst(strtolower($k)), is_array($v) ? json_encode($v) : $v);
             }, $event->getContext(), array_keys($event->getContext()))) . ']';
         } else {
             $message .= ' [Context: ' . json_encode($event->getContext()) . ']';
         }
     }
     $this->data['log'][] = ['time' => $event->getDate()->format('U.u'), 'level' => $event->getLevel(), 'message' => $message];
 }
Esempio n. 6
0
 /**
  * {@inheritdoc}
  */
 protected function send(Event $event) : bool
 {
     $message = $event->format(false);
     openlog($this->name, LOG_ODELAY, $this->facility);
     $return = syslog($this->convertType($event->getLevel()), $message);
     closelog();
     return $return;
 }
Esempio n. 7
0
 /**
  * {@inheritdoc}
  */
 protected function send(Event $event) : bool
 {
     file_put_contents($this->path, $event->format(), FILE_APPEND);
     return true;
 }
Esempio n. 8
0
 /**
  * {@inheritdoc}
  */
 protected function send(Event $event) : bool
 {
     file_put_contents('php://stderr', $event->format());
     return true;
 }