Example #1
0
 /**
  * @param DomainEvent $event
  * @param EventHandlerInterface $eventHandler
  */
 public function onEventQueueingSuccess(DomainEvent $event, EventHandlerInterface $eventHandler)
 {
     $eventType = new ObjectName($event);
     $eventHandlerType = new ObjectName($eventHandler);
     $additionalData = ['status' => 'success', 'type' => 'event', 'handlerType' => $eventHandlerType->getName(), 'command' => $this->getEventData($event)];
     $this->logger->log(sprintf('%s queueing success', $eventType), LOG_INFO, $additionalData, 'ES.Event');
 }
 public function log($message, $priority = LOG_INFO, $extras = array())
 {
     // All guzzle logs should be DEBUG, regardless of its own priority.
     if (LogFactory::isDebugEnabled()) {
         $this->logger->log(LogLevel::DEBUG, $message, $extras);
     }
 }
 /**
  *
  * {@inheritDoc}
  *
  * @see \Nia\Logging\LoggerInterface::log($message, $context)
  */
 public function log(string $message, array $context) : LoggerInterface
 {
     if (mb_strpos($message, $this->needle) === false) {
         $this->logger->log($message, $context);
     }
     return $this;
 }
Example #4
0
 /**
  * Log using our assigned logger
  *
  * @param string $level   LogLevel
  * @param string $message Message to log
  * @param array  $context optional additional log data
  *
  * @return void
  */
 public static function log($level, $message, array $context = array())
 {
     if (is_null(self::$_logger)) {
         self::setFallbackLogger();
     }
     if (!is_null(self::$_logger)) {
         self::$_logger->log($level, $message, $context);
     } else {
         // unable to log anywhere
         echo $message;
     }
 }
Example #5
0
 /**
  * Logs with an arbitrary level.
  *
  * @param mixed   $level    PSR-3 log level constant, or equivalent string
  * @param string  $message  Message to log, may contain a { placeholder }
  * @param array   $context  Variables to replace { placeholder }
  * @return null
  */
 public function log($level, $message, array $context = array())
 {
     if (!empty($this->logger)) {
         $this->logger->log($level, $this->interpolate($message, $context));
     } else {
         if ($this->verbose) {
             fwrite(STDOUT, '[' . $level . '] [' . strftime('%T %Y-%m-%d') . '] ' . $this->interpolate($message, $context) . PHP_EOL);
             return;
         }
         if (!($level === Psr\Log\LogLevel::INFO || $level === Psr\Log\LogLevel::DEBUG)) {
             fwrite(STDOUT, '[' . $level . '] ' . $this->interpolate($message, $context) . PHP_EOL);
         }
     }
 }
Example #6
0
File: Client.php Project: jyxo/php
 /**
  * Sends a request.
  *
  * @param string $path Request path
  * @param string $method Request method
  * @param array $headers Array of headers
  * @return \GuzzleHttp\Psr7\Response
  * @throws \Jyxo\Webdav\Exception On error
  */
 protected function sendRequest(string $path, string $method, array $headers = []) : \GuzzleHttp\Psr7\Response
 {
     try {
         // Send request to a random server
         $request = $this->createRequest($this->getRandomServer(), $path, $method, $headers);
         $response = $this->createClient()->send($request, $this->requestOptions);
         if (null !== $this->logger) {
             $this->logger->log(sprintf("%s %d %s", $request->getMethod(), $response->getStatusCode(), $request->getUri()));
         }
         return $response;
     } catch (\GuzzleHttp\Exception\GuzzleException $e) {
         throw new Exception($e->getMessage(), 0, $e);
     }
 }
Example #7
0
 /**
  * Sends a request.
  *
  * @param string $path Request path
  * @param integer $method Request method
  * @param array $headers Array of headers
  * @return \http\Client\Response
  * @throws \Jyxo\Webdav\Exception On error
  */
 protected function sendRequest($path, $method, array $headers = array())
 {
     try {
         // Send request to a random server
         $request = $this->createRequest($this->getRandomServer(), $path, $method, $headers);
         $client = new \http\Client();
         $client->enqueue($request);
         $client->send();
         $response = $client->getResponse();
         if (null !== $this->logger) {
             $this->logger->log(sprintf("%s %d %s", $request->getRequestMethod(), $response->getResponseCode(), $request->getRequestUrl()));
         }
         return $response;
     } catch (\http\Exception $e) {
         throw new Exception($e->getMessage(), 0, $e);
     }
 }
Example #8
0
 /**
  * Insert/Update an Api on the database
  * @param Auth $auth
  * @throws Exception
  * @return RestResponse
  */
 public function setAuth(Auth &$auth, $insertMode = FALSE)
 {
     $method = "PUT";
     $url = E3_PROV_URL_AUTH . "/" . rawurlencode($auth->getId());
     if ($insertMode) {
         $method = "POST";
         $url = E3_PROV_URL_AUTH;
     }
     /**
      * Send the XML payload the the Provisioning Backend
      */
     LoggerInterface::log(($insertMode ? "Creating" : "Updating") . " Auth: {$auth->toXML()}\nEndpoint: ({$method}) {$url}", LoggerInterface::INFO);
     $reply = $this->restClient->makeCall($url, $method, $auth->toXML());
     if ($insertMode) {
         if ($auth->getId() == NULL) {
             $xml = simplexml_load_string($reply->getPayload());
             $auth->setId((string) $xml->id);
         }
     }
     return $reply;
 }
Example #9
0
 /**
  *
  * Make a cURL call
  * @param string $endpoint		URL to call
  * @param string $method			HTTP Method used for the call
  * @param string/Array $payload	Body message to send with the call
  * @throws Exception
  * @return RestResponse
  */
 public function makeCall($path, $method = "GET", $payload = "")
 {
     try {
         if (strpos($path, "/") !== 0) {
             $path = "/" . $path;
         }
         $endpoint = $this->protocol . "://" . $this->host . ":" . $this->port . $path;
         // Initialize the curl_session with targeted URL
         $ch = curl_init($endpoint);
         // Throw exception if curl is not initialize
         if ($ch == FALSE) {
             throw new CURLException("CURL Not available");
         }
         // Set the content type depending the payload type
         if (is_array($payload)) {
             $contentType = "multipart/form-data";
         } else {
             $contentType = "application/xml; charset=UTF-8";
         }
         // Set global headers for the call
         $headers = array('Cache-Control: nocache', 'Accept: application/xml', 'Content-Type: ' . $contentType, 'Connection: Keep-Alive');
         if (!empty($this->basicauth)) {
             $arr = explode(":", $this->basicauth, 2);
             $username = $arr[0];
             $password = $arr[1];
             $headers[] = $this->genAuthHeaderBasic($username, $password);
         }
         if (!empty($this->peerCertificatePath)) {
             // This will probably work, but I won't know until it's tested.
             // Until it's reliably tested, skip execution with an exception.
             throw new Exception("Not tested!");
             curl_setopt($ch, CURLOPT_CAINFO, $this->{$peerCertificatePath});
             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
             curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
         }
         // Set cURL options for the call
         curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
         curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($method));
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
         curl_setopt($ch, CURLOPT_HEADER, TRUE);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, self::CONNECT_TIMEOUT);
         // Execute the call
         $return = curl_exec($ch);
         // Close cURL session
         curl_close($ch);
         // Check if endpoint is unavailable
         if ($return == FALSE) {
             $err = "No Server Responding";
             LoggerInterface::log($err, LoggerInterface::ERROR);
             throw new CURLException($err);
         }
         // Implements a new RestResponse to store useful informations
         $response = new RestResponse();
         // Retrieve useful informations from REST call response
         // Extract the HTTP Code
         $response->setHTTPCode($this->getHTTPCode($return));
         // Extract the specific X-E3-Application-Error-Code used for functionnal errors
         $response->setXApplicationCode($this->getSpecificApplicationCode($return));
         // Extract the payload
         $response->setPayload($this->getBody($return));
         // Throw Exception if BackEnd retrieve functionnal error
         if ($response->getXApplicationCode() !== NULL && $response->getXApplicationCode() != 200) {
             $errorMessage = "E3_API_Err_" . $response->getXApplicationCode();
             throw new RESTAppException($errorMessage, $response->getXApplicationCode());
         }
         // Throw Exception if BackEnd retrieve HTTP error
         if (false && !in_array($response->getHTTPCode(), array(200, 201, 202, 203, 204))) {
             if ($response->getHTTPCode() == 404) {
                 $errorMessage = '404 - Server Unreachable';
             } else {
                 $errorXML = simplexml_load_string($response->getPayload());
                 if ($errorXML->status == "SUCCESS") {
                     LoggerInterface::log("Response successful with improper return code ({$response->getHTTPCode()}): " . print_r($response->getPayload(), true), LoggerInterface::WARN);
                     return $response;
                 }
                 LoggerInterface::log("Errored response: ({$response->getHTTPCode()}) " . print_r($response->getPayload(), true), LoggerInterface::DEBUG);
                 $errorMessage = $errorXML->error->errorText;
                 //$errorMessage = htmlspecialchars($response->getPayload());
             }
             throw new Exception($errorMessage, $response->getHTTPCode());
         }
         // Return the formatted response object
         return $response;
     } catch (Exception $e) {
         LoggerInterface::log('Rest Curl Call', $e->getMessage(), array(), LoggerInterface::ERROR);
         //drupal_set_message('An error as occured during the operation, please retry or contact an administrator.', 'error');
         throw new Exception($e->getMessage());
     }
 }
Example #10
0
 /**
  * Logging exception
  *
  * @return int
  */
 public function handle()
 {
     $e = $this->getException();
     $this->logger->log($e instanceof \Error ? LogLevel::CRITICAL : LogLevel::ERROR, $e->getMessage(), ['exception' => $e]);
     return self::DONE;
 }
Example #11
0
 /**
  * do something ...
  */
 public function doSomething()
 {
     // no more check "if (!is_null($this->logger))..." with the NullObject pattern
     $this->logger->log('We are in ' . __METHOD__);
     // something to do...
 }
 private function _deleteCRL($crl_id)
 {
     $method = "DELETE";
     $url = E3_PROV_URL_TRUSTSTORE . "/crls/" . rawurlencode($crl_id);
     LoggerInterface::log("Deleting CRL '{$crl_id}' with DELETE: {$url}", LoggerInterface::INFO);
     $reply = $this->restClient->makeCall($url, $method);
     $xml = simplexml_load_string($reply->getPayload());
     if ($reply->getHTTPCode() === "200") {
         return true;
     } else {
         throw new Exception(!empty($xml->error) ? $xml->error->errorText : UNDEFINED_ERROR_TEXT);
     }
 }
 /**
  * If no param, returns last error
  * If param is exception, logs exception and sets error
  * If param is String, sets error
  *
  * @static
  * @param null $err
  * @return mixed
  */
 public static function error($err = null)
 {
     if ($err == null) {
         return LoggingManager::$error;
     }
     if ($err instanceof Exception) {
         LoggingManager::$error = $err->getMessage();
         LoggerInterface::logException($err, LoggerInterface::ERROR);
     } else {
         LoggingManager::$error = $err;
         LoggerInterface::log($err, LoggerInterface::ERROR);
     }
 }
Example #14
0
 public static function logError($errno, $errstr, $errfile = '', $errline = '', $errcontext = null)
 {
     $poErrorLevel = LoggerInterface::WARN;
     $errnostr = "Unknown";
     switch ($errno) {
         case E_ERROR:
             $errnostr = 'Error';
             $poErrorLevel = LoggerInterface::ERROR;
             break;
         case E_WARNING:
             $errnostr = 'Warning';
             $poErrorLevel = LoggerInterface::WARN;
             break;
         case E_PARSE:
             $errnostr = 'Parsing Error';
             $poErrorLevel = LoggerInterface::ERROR;
             break;
         case E_NOTICE:
             $errnostr = 'Notice';
             $poErrorLevel = LoggerInterface::NOTICE;
             break;
         case E_CORE_ERROR:
             $errnostr = 'Core Error';
             $poErrorLevel = LoggerInterface::CRITICAL;
             break;
         case E_CORE_WARNING:
             $errnostr = 'Core Warning';
             $poErrorLevel = LoggerInterface::ERROR;
             break;
         case E_COMPILE_ERROR:
             $errnostr = 'Compile Error';
             $poErrorLevel = LoggerInterface::CRITICAL;
             break;
         case E_COMPILE_WARNING:
             $errnostr = 'Compile Warning';
             $poErrorLevel = LoggerInterface::ERROR;
             break;
         case E_USER_ERROR:
             $errnostr = 'User Error';
             $poErrorLevel = LoggerInterface::ERROR;
             break;
         case E_USER_WARNING:
             $errnostr = 'User Warning';
             $poErrorLevel = LoggerInterface::WARN;
             break;
         case E_USER_NOTICE:
             $errnostr = 'User Notice';
             $poErrorLevel = LoggerInterface::NOTICE;
             break;
         case E_STRICT:
             $errnostr = 'Runtime Notice';
             $poErrorLevel = LoggerInterface::DEBUG;
             break;
         case E_RECOVERABLE_ERROR:
             $errnostr = 'Catchable Fatal Error';
             $poErrorLevel = LoggerInterface::ERROR;
             break;
     }
     LoggerInterface::log("{$errnostr}: {$errfile}({$errline}): {$errstr}", $poErrorLevel);
 }
 /**
  * do something ...
  */
 public function doSomething()
 {
     // notice here that you don't have to check if the logger is set with eg. is_null(), instead just use it
     $this->logger->log('We are in ' . __METHOD__);
 }
Example #16
0
 /**
  * @param Command $command
  * @param CommandHandlerInterface $commandHandler
  * @param \Exception $exception
  * @return void
  */
 public function onCommandHandlingFailure(Command $command, CommandHandlerInterface $commandHandler, \Exception $exception)
 {
     $commandHandlerType = new ObjectName($commandHandler);
     $additionalData = ['status' => 'failure', 'type' => 'command', 'handlerType' => $commandHandlerType->getName(), 'command' => $this->getCommandData($command), 'exception' => ['message' => $exception->getMessage(), 'file' => $exception->getFile(), 'class' => get_class($exception), 'line' => $exception->getLine(), 'code' => $exception->getCode()]];
     $this->logger->log(sprintf('%s handling failure', $command), LOG_ERR, $additionalData, 'ES.Command');
 }
Example #17
0
 /**
  *
  * Insert/Update an Api on the database
  * @param Api $api
  * @throws Exception
  */
 public function setApi(Api &$api, $insertMode = FALSE)
 {
     $method = "PUT";
     $path = "/cxf/e3/prov/v1/apis/" . rawurlencode($api->getId());
     if ($insertMode) {
         $method = "POST";
         $path = "/cxf/e3/prov/v1/apis/";
     }
     /**
      * Send the XML payload the the Provisioning Backend
      */
     $api->toXML();
     LoggerInterface::log(($insertMode ? "Creating" : "Updating") . " API: {$api->toXML()}\nEndpoint: ({$method}) {$path}", LoggerInterface::INFO);
     $reply = $this->restClient->makeCall($path, $method, $api->toXML());
     $xml = simplexml_load_string($reply->getPayload());
     $api->setId((string) $xml->id);
     return $xml;
 }