Example #1
0
 public function __construct($callableString)
 {
     if (!is_callable($callableString)) {
         LoggerPolicy::processConfigurationError("'{$callableString}' is not callable");
         return;
     }
     $this->callable = $callableString;
 }
 public static function setIoErrorPolicy($policy)
 {
     try {
         parent::setIoErrorPolicy($policy);
     } catch (\Mougrim\Logger\LoggerConfigurationException $exception) {
         throw new LoggerConfigurationException($exception->getMessage(), $exception->getCode(), $exception);
     }
 }
Example #3
0
 public function getLayout($name)
 {
     if (!isset($this->layoutMap[$name])) {
         LoggerPolicy::processConfigurationError("Layout {$name} not found");
         return new LayoutSimple();
     }
     return $this->layoutMap[$name];
 }
Example #4
0
 public function __construct($path)
 {
     if ($path) {
         $this->path = preg_split('/\\./', $path, -1, PREG_SPLIT_NO_EMPTY);
     }
     if (!$this->path) {
         LoggerPolicy::processConfigurationError('path is required');
         $this->path = [];
     }
 }
Example #5
0
 public function write($priority, $message)
 {
     $socket = fsockopen($this->host, $this->port, $errorCode, $errorMessage, $this->timeout);
     if ($socket === false) {
         LoggerPolicy::processIOError("Could not open socket to {$this->host}:{$this->port} – {$errorCode} {$errorMessage}. Closing appender.");
         return;
     }
     $write = fwrite($socket, $message);
     fclose($socket);
     if ($write === false) {
         LoggerPolicy::processIOError("Error writing to socket to {$this->host}:{$this->port}");
         return;
     }
 }
Example #6
0
 /**
  * @param string $streamName
  *
  * @throws LoggerConfigurationException
  */
 public function setStream($streamName)
 {
     switch ($streamName) {
         case 'STDOUT':
             $this->stream = self::STDOUT;
             return;
         case 'STDERR':
             $this->stream = self::STDERR;
             return;
         default:
             LoggerPolicy::processConfigurationError("Stream must be STDOUT or STDERR, got '{$streamName}'");
             return;
     }
 }
 protected function tearDown()
 {
     SoftMocks::restoreAll();
     parent::tearDown();
     LoggerPolicy::reset();
 }
Example #8
0
 /**
  * Reset all loggers, appenders, etc.
  */
 public static function reset()
 {
     self::$hierarchy = new LoggerHierarchy();
     self::$isConfigured = false;
     LoggerNDC::clear();
     LoggerMDC::clear();
     LoggerRender::reset();
     LoggerPolicy::reset();
 }
 private function createObject(array $config)
 {
     if (!isset($config['class'])) {
         $message = 'Key "class" is required';
         switch (LoggerPolicy::getConfigurationErrorPolicy()) {
             case LoggerPolicy::POLICY_EXIT:
                 exit($message);
             case LoggerPolicy::POLICY_EXCEPTION:
             default:
                 throw new LoggerConfigurationException($message);
         }
     }
     $reflection = new \ReflectionClass($config['class']);
     unset($config['class']);
     $params = [];
     $constructor = $reflection->getConstructor();
     if ($constructor) {
         foreach ($constructor->getParameters() as $param) {
             $params[$param->getName()] = null;
             if ($param->isDefaultValueAvailable()) {
                 $params[$param->getName()] = $param->getDefaultValue();
             }
             if (isset($config[$param->getName()])) {
                 $params[$param->getName()] = $config[$param->getName()];
                 unset($config[$param->getName()]);
             }
         }
         $object = $reflection->newInstanceArgs($params);
     } else {
         $object = $reflection->newInstance();
     }
     foreach ($config as $name => $value) {
         $method = 'set' . $name;
         if (method_exists($object, $method)) {
             $object->{$method}($value);
         }
     }
     return $object;
 }
Example #10
0
 /**
  * @return resource
  *
  * @throws LoggerIOException
  */
 private function getStream()
 {
     if ($this->stream && get_resource_type($this->stream) === 'Unknown') {
         fclose($this->stream);
         $this->stream = null;
     }
     if (!$this->stream) {
         $this->stream = @fopen($this->streamUrl, 'a');
         if (!$this->stream) {
             LoggerPolicy::processIOError("Error open {$this->streamUrl}");
             $this->stream = null;
         }
     }
     return $this->stream;
 }