Exemplo n.º 1
0
 /**
  * {@inheritDoc}
  */
 protected function write(LogEntryInterface $logEntry)
 {
     $ident = $logEntry->getChannel();
     if (!openlog($ident, $this->logopts, $this->facility)) {
         throw new LogicException(Message::get(Message::LOG_SYSLOG_FAIL, $ident, $this->facility), Message::LOG_SYSLOG_FAIL);
     }
     syslog($this->priorities[$logEntry->getLevel()], $logEntry->getFormatted());
 }
Exemplo n.º 2
0
 /**
  * Constructor
  *
  * @param  string|resource $stream the stream
  * @param  FormatterInterface $formatter
  * @param  bool $stopPropagation
  * @access public
  * @since  2.0.1 removed level param
  */
 public function __construct($stream, FormatterInterface $formatter = null, $stopPropagation = false)
 {
     // open stream
     $strm = $this->openStream($stream);
     if (!is_resource($strm)) {
         throw new LogicException(Message::get(Message::LOG_STREAM_FAIL, $stream), Message::LOG_STREAM_FAIL);
     }
     $this->stream = $strm;
     parent::__construct($formatter, $stopPropagation);
 }
Exemplo n.º 3
0
 /**
  * Constructor
  *
  * @param  string $stream the stream
  * @param  bool $color use ANSI color formatter or not
  * @param  FormatterInterface $formatter
  * @param  bool $stopPropagation
  * @access public
  * @since  2.0.1 removed level param
  */
 public function __construct($stream = 'php://stderr', $color = true, FormatterInterface $formatter = null, $stopPropagation = false)
 {
     if ($this->isCliMode()) {
         $this->color = (bool) $color;
         if (!in_array($stream, ['php://stderr', 'php://stdout'])) {
             throw new LogicException(Message::get(Message::LOG_STREAM_INVALID, $stream), Message::LOG_STREAM_INVALID);
         }
         parent::__construct($stream, $formatter, $stopPropagation);
     }
 }
Exemplo n.º 4
0
 /**
  * Check file path
  *
  * @param  string $path
  * @throws LogicException if directory failure etc.
  * @access protected
  */
 protected function checkPath($path)
 {
     // get the directory
     $dir = dirname(realpath($path));
     if (!is_dir($dir)) {
         mkdir($dir, 0777, true);
     }
     if (!is_dir($dir) || !is_writable($dir)) {
         throw new LogicException(Message::get(Message::MSG_PATH_NONWRITABLE, $dir), Message::MSG_PATH_NONWRITABLE);
     }
 }
Exemplo n.º 5
0
 /**
  * {@inheritDoc}
  */
 public function setLevel($level = PsrLogLevel::INFO)
 {
     if (!isset(LogLevel::$levels[$level])) {
         throw new InvalidArgumentException(Message::get(Message::LOG_LEVEL_INVALID, $level), Message::LOG_LEVEL_INVALID);
     }
     $this->level = $level;
     return $this;
 }
Exemplo n.º 6
0
 /**
  * Add handler to the channel with priority
  *
  * @param  string $level the level this handler is handling
  * @param  callable $handler
  * @param  string $channel channel to listen to
  * @param  int $priority
  * @return $this
  * @access public
  * @since  2.0.1 added level param
  * @api
  */
 public function addHandler($level, callable $handler, $channel = '*', $priority = 0)
 {
     // check level
     if (!isset(LogLevel::$levels[$level])) {
         throw new InvalidArgumentException(Message::get(Message::LOG_LEVEL_INVALID, $level), Message::LOG_LEVEL_INVALID);
     }
     return $this->addCallable('handlers', $handler, $channel, $priority, $level);
 }