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);
     }
 }
Example #2
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');
 }
 /**
  *
  * {@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
 public function send($mailTemplate, $recipient, $tag, array $args)
 {
     $subject = $this->mailLoader->getSubject($mailTemplate);
     $message = Swift_Message::newInstance()->setSubject($subject)->setFrom($this->sourceMail)->setTo($recipient);
     $message->setBody($this->tpl->render($mailTemplate, $args), 'text/html');
     $this->mailer->send($message);
     $this->log->info('Sent mail message of type \'' . $mailTemplate . '\': ' . $tag);
 }
Example #5
0
 /**
  * Set the location for language files.
  *
  * @param String $location Path to locale files
  *
  * @return void
  */
 public function set_locales_location($location)
 {
     if (file_exists($location) === TRUE) {
         $this->locales_location = $location;
     } else {
         $this->logger->warning('Invalid locales location: ' . $location);
     }
 }
Example #6
0
 /**
  * Testcase Constructor.
  *
  * @return void
  */
 public function setUpError()
 {
     $this->logger = $this->getMock('Psr\\Log\\LoggerInterface');
     $response = FALSE;
     $this->logger->expects($this->once())->method('warning')->with($this->equalTo('Sending email notification to {endpoint} failed.'), $this->equalTo(['endpoint' => '12345679']));
     $this->class = new EmailResponse($response, $this->logger, '12345679');
     $this->reflection = new ReflectionClass('Lunr\\Vortex\\Email\\EmailResponse');
 }
Example #7
0
 /**
  * Constructor.
  *
  * @param Boolean         $response Response of the Mail Class.
  * @param LoggerInterface $logger   Shared instance of a Logger.
  * @param String          $email    The email address that the message was sent to.
  */
 public function __construct($response, $logger, $email)
 {
     if ($response === TRUE) {
         $this->status = PushNotificationStatus::SUCCESS;
     } else {
         $this->status = PushNotificationStatus::ERROR;
         $context = ['endpoint' => $email];
         $logger->warning('Sending email notification to {endpoint} failed.', $context);
     }
 }
Example #8
0
 /**
  * Testcase Constructor.
  *
  * @return void
  */
 public function setUpInvalidXMLError()
 {
     $this->logger = $this->getMock('Psr\\Log\\LoggerInterface');
     $response = $this->getMockBuilder('Lunr\\Network\\CurlResponse')->disableOriginalConstructor()->getMock();
     $response->expects($this->once())->method('get_network_error_number')->will($this->returnValue(0));
     $map = [['http_code', 200]];
     $response->expects($this->exactly(1))->method('__get')->will($this->returnValueMap($map));
     $this->logger->expects($this->once())->method('warning')->with($this->equalTo('Parsing response of push notification to {endpoint} failed: {error}'), $this->equalTo(['error' => 'Invalid document end', 'endpoint' => '12345679']));
     $this->class = new PAPResponse($response, $this->logger, '12345679');
     $this->reflection = new ReflectionClass('Lunr\\Vortex\\PAP\\PAPResponse');
 }
Example #9
0
 /**
  * Testcase Constructor.
  *
  * @return void
  */
 public function setUpError()
 {
     $this->logger = $this->getMock('Psr\\Log\\LoggerInterface');
     $response = $this->getMockBuilder('Lunr\\Network\\CurlResponse')->disableOriginalConstructor()->getMock();
     $response->expects($this->once())->method('get_network_error_number')->will($this->returnValue(-1));
     $response->expects($this->once())->method('get_network_error_message')->will($this->returnValue('Error Message'));
     $map = [['http_code', 503]];
     $response->expects($this->exactly(1))->method('__get')->will($this->returnValueMap($map));
     $this->logger->expects($this->once())->method('warning')->with($this->equalTo('Dispatching push notification to {endpoint} failed: {error}'), $this->equalTo(['error' => 'Error Message', 'endpoint' => '12345679']));
     $this->class = new GCMResponse($response, $this->logger, '12345679');
     $this->reflection = new ReflectionClass('Lunr\\Vortex\\GCM\\GCMResponse');
 }
Example #10
0
 /**
  * Connects to the websocket
  *
  * @param boolean $keepAlive keep alive the connection (not supported yet) ?
  * @return $this
  */
 public function initialize($keepAlive = false)
 {
     try {
         $this->engine->connect();
         $this->isConnected = true;
         if (true === $keepAlive) {
             $this->engine->keepAlive();
         }
     } catch (SocketException $e) {
         $this->logger->error('Could not connect to the server', ['exception' => $e]);
         throw $e;
     }
     return $this;
 }
Example #11
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 #12
0
 /**
  * Set notification status information.
  *
  * @param String          $endpoint The notification endpoint that was used.
  * @param LoggerInterface $logger   Shared instance of a Logger.
  *
  * @return void
  */
 private function set_status($endpoint, $logger)
 {
     switch ($this->http_code) {
         case 200:
             $this->status = PushNotificationStatus::SUCCESS;
             break;
         case 400:
             $this->status = PushNotificationStatus::ERROR;
             break;
         case 401:
             $this->status = PushNotificationStatus::INVALID_ENDPOINT;
             break;
         case 503:
             $this->status = PushNotificationStatus::ERROR;
             break;
         default:
             $this->status = PushNotificationStatus::UNKNOWN;
             break;
     }
     if ($this->status !== PushNotificationStatus::SUCCESS) {
         $context = ['endpoint' => $endpoint, 'code' => $this->status, 'description' => $this->result];
         $message = 'Push notification delivery status for endpoint {endpoint}: ';
         $message .= 'failed with an error: {description}. Error #{code}';
         $logger->warning($message, $context);
     } else {
         $failures = $this->parse_gcm_failures();
         if ($failures['failure'] != 0) {
             $context = ['failure' => $failures['failure'], 'errors' => json_encode($failures['messages'])];
             $message = '{failure} push notification(s) failed with the following ';
             $message .= 'error information {errors}.';
             $logger->warning($message, $context);
         }
     }
 }
Example #13
0
 public function shutdownAllChildren()
 {
     foreach ($this->children as $child) {
         posix_kill($child, SIGTERM);
     }
     $time = microtime(true);
     do {
         foreach ($this->children as $child) {
             $pid = pcntl_waitpid($child, $status, WNOHANG);
             if ($pid) {
                 unset($this->children[$pid]);
                 $this->childrenCount--;
             }
         }
         if ($this->childrenCount === 0) {
             break;
         }
         usleep(1000);
     } while (microtime(true) - $time < $this->childExitTimeout);
     if ($this->childrenCount) {
         $this->logger->warning(sprintf('%d children failed to exit within the %ds limit, going to kill them', $this->childrenCount, $this->childExitTimeout));
         foreach ($this->children as $child) {
             posix_kill($child, SIGKILL);
         }
     }
 }
Example #14
0
 public function setUp()
 {
     $configFile = __DIR__ . '/../../config.yml';
     $value = Yaml::parse(file_get_contents($configFile));
     $this->ariAddress = $value['tests']['ari_address'];
     $this->amiAddress = $value['tests']['ami_address'];
     $this->dialString = $value['tests']['dial_string'];
     $this->logger = new \Zend\Log\Logger();
     $logWriter = new \Zend\Log\Writer\Stream("php://output");
     $this->logger->addWriter($logWriter);
     //$filter = new \Zend\Log\Filter\SuppressFilter(true);
     $filter = new \Zend\Log\Filter\Priority(\Zend\Log\Logger::NOTICE);
     $logWriter->addFilter($filter);
     $this->client = new Phparia($this->logger);
     $this->client->connect($this->ariAddress, $this->amiAddress);
 }
Example #15
0
 /**
  * Set notification status information.
  *
  * @param String          $endpoint The notification endpoint that was used.
  * @param LoggerInterface $logger   Shared instance of a Logger.
  *
  * @return void
  */
 private function set_status($endpoint, $logger)
 {
     switch ($this->response_code) {
         case APNSStatus::APN_SUCCESS:
             $this->status = PushNotificationStatus::SUCCESS;
             break;
         case APNSStatus::APN_ERR_TOKEN_IS_NOT_SET:
         case APNSStatus::APN_ERR_TOKEN_INVALID:
             $this->status = PushNotificationStatus::INVALID_ENDPOINT;
             break;
         case APNSStatus::APN_ERR_PROCESSING_ERROR:
             $this->status = PushNotificationStatus::TEMPORARY_ERROR;
             break;
         case APNSStatus::APN_ERR_UNKNOWN:
             $this->status = PushNotificationStatus::UNKNOWN;
             break;
         default:
             $this->status = PushNotificationStatus::ERROR;
             break;
     }
     if ($this->status !== PushNotificationStatus::SUCCESS) {
         $context = ['endpoint' => $endpoint, 'code' => $this->status, 'description' => $this->result];
         $message = 'Push notification delivery status for endpoint {endpoint}: ';
         $message .= 'failed with an error: {description}. Error #{code}';
         $logger->warning($message, $context);
     }
 }
 /**
  * @param LoggerInterface
  */
 public static function addHelpers(LoggerInterface $logger)
 {
     $self = get_called_class();
     $ref = new \ReflectionClass($self);
     $methods = $ref->getMethods(\ReflectionMethod::IS_STATIC);
     $classParts = explode('\\', $self);
     array_pop($classParts);
     $namespace = implode('\\', $classParts);
     foreach ($methods as $method) {
         $name = $method->getName();
         if (strpos($name, 'on') === 0) {
             $eventName = substr($name, 2);
             $eventClass = $namespace . '\\' . $eventName;
             $logger->addHelper($eventClass, array($self, $name));
         }
     }
 }
function func(GearmanJob $job)
{
    $data = json_decode($job->workload(), true);
    // ไธดๆ—ถๅ…ณ้—ญLogger
    $tmpEnable = GlobalConfig::$LOGGER_ENABLE;
    GlobalConfig::$LOGGER_ENABLE = false;
    LoggerInterface::save($data);
    GlobalConfig::$LOGGER_ENABLE = $tmpEnable;
}
Example #18
0
 /**
  * Removes all payment rules from the db
  */
 public function removePaymentRules($paymentId)
 {
     $sql = "DELETE FROM `s_core_rulesets` WHERE `paymentID` = ?";
     try {
         Shopware()->Db()->query($sql, array($paymentId));
     } catch (Exception $exception) {
         $this->log->error("There was an Error removing the payment rules: " . $exception->getMessage());
         throw new Exception("There was an Error removing the payment rules: " . $exception->getMessage());
     }
 }
Example #19
0
 public function prepare()
 {
     if (headers_sent()) {
         return $this;
     }
     $this->setProtocol($this->sc);
     $this->Logger->info("STATUS: {$this->sc}");
     $this->prepareResponse();
     return $this;
 }
Example #20
0
 /**
  * Set deeplink for the toast notification.
  *
  * @param String $deeplink Deeplink
  *
  * @return MPNSToastPayload $self Self Reference
  */
 public function set_deeplink($deeplink)
 {
     $deeplink = $this->escape_string($deeplink);
     if (strlen($deeplink) > 256) {
         $deeplink = substr($deeplink, 0, 256);
         $this->logger->notice('Deeplink for Windows Phone Toast Notification too long. Truncated.');
     }
     $this->elements['deeplink'] = $deeplink;
     return $this;
 }
Example #21
0
 /**
  * @param array $injectors
  */
 public function __construct(array $injectors = array())
 {
     parent::__construct($injectors);
     if (!$this->injectors['client']) {
         $this->injectors['client'] = new \MongoClient($this->injectors['dsn'], $this->injectors['options']);
     }
     // Set client and collection
     $this->client = $this->injectors['client'];
     $this->collection = $this->client->selectCollection($this->injectors['database'], $this->injectors['collection']);
 }
Example #22
0
 /**
  * Set the value of silentConsole member
  *
  * @param boolean $silentConsole
  *
  * @return void
  */
 public static function setSilentConsole($silentConsole)
 {
     if ($silentConsole === true && method_exists(self::$_logger, 'setSilentConsole')) {
         self::$_logger->setSilentConsole(true);
     } else {
         if (method_exists(self::$_logger, 'setSilentConsole')) {
             self::$_logger->setSilentConsole(false);
         }
     }
     self::$silentConsole = $silentConsole;
 }
Example #23
0
 /**
  * @param array $injectors
  */
 public function __construct(array $injectors = array())
 {
     parent::__construct($injectors);
     if (!$this->injectors['client']) {
         $this->injectors['client'] = new \Redis();
         $this->injectors['client']->connect($this->injectors['host'], $this->injectors['port']);
         $this->injectors['client']->select($this->injectors['db']);
     }
     // Save client
     $this->client = $this->injectors['client'];
 }
Example #24
0
 public function run_command($args, $assoc_args = array())
 {
     try {
         list($command, $final_args, $cmd_path) = $this->find_command_to_run($args);
         $name = implode(' ', $cmd_path);
         if (isset($this->extra_config[$name])) {
             $extra_args = $this->extra_config[$name];
         } else {
             $extra_args = array();
         }
         $command->invoke($final_args, $assoc_args, $extra_args);
     } catch (\Exception $e) {
         if (method_exists($e, 'getReplacements')) {
             $this->logger->error($e->getMessage(), $e->getReplacements());
         } else {
             $this->logger->error($e->getMessage());
         }
         exit(1);
     }
 }
Example #25
0
File: API.php Project: m6w6/seekat
 /**
  * Queue the actual HTTP transfer through \seekat\API\Deferred and return the promise
  *
  * @param string $method The HTTP request method
  * @param mixed $args The HTTP query string parameters
  * @param mixed $body Thee HTTP message's body
  * @param array $headers The request's additional HTTP headers
  * @return ExtendedPromiseInterface
  */
 private function __xfer(string $method, $args = null, $body = null, array $headers = null) : ExtendedPromiseInterface
 {
     if (isset($this->__data)) {
         $this->__log->debug(__FUNCTION__ . "({$method}) -> resolve", ["url" => (string) $this->__url, "args" => $args, "body" => $body, "headers" => $headers]);
         return resolve($this);
     }
     $url = $this->__url->mod(["query" => new QueryString($args)]);
     $request = new Request($method, $url, (array) $headers + $this->__headers, $body = is_array($body) ? json_encode($body) : (is_resource($body) ? new Body($body) : (is_scalar($body) ? (new Body())->append($body) : $body)));
     $this->__log->info(__FUNCTION__ . "({$method}) -> request", ["url" => (string) $this->__url, "args" => $this->__url->query, "body" => $body, "headers" => $headers]);
     return (new Call($this, $this->__client, $request))->promise();
 }
Example #26
0
 /**
  * Checks for new versions of Terminus once per week and saves to cache
  *
  * @return [void]
  */
 private function checkForUpdate()
 {
     $cache_data = $this->cache->get_data('latest_release', array('decode_array' => true));
     if (!$cache_data || (int) $cache_data['check_date'] < (int) strtotime('-7 days')) {
         $current_version = $this->checkCurrentVersion();
     } else {
         $current_version = $cache_data['version'];
     }
     if (version_compare($cache_data['version'], TERMINUS_VERSION, '>')) {
         $this->logger->info('An update to Terminus is available. Please update to {version}.', array('version' => $cache_data['version']));
     }
 }
Example #27
0
 /**
  * Get specific cell of the first row of the query result.
  *
  * @param DatabaseQueryResult $query The result of the run query
  * @param String              $cell  The title of the requested cell
  *
  * @return mixed $return FALSE on failure, mixed otherwise
  */
 protected function result_cell($query, $cell)
 {
     if ($query->has_failed() === TRUE) {
         $context = ['query' => $query->query(), 'error' => $query->error_message()];
         $this->logger->error('{query}; failed with error: {error}', $context);
         return FALSE;
     }
     if ($query->number_of_rows() == 0) {
         return '';
     } else {
         return $query->result_cell($cell);
     }
 }
Example #28
0
 /**
  * Fetch and parse results as though they were a json string.
  *
  * @param String $url    API URL
  * @param Array  $params Array of parameters for the API request
  *
  * @return Array $parts Array of return values
  */
 protected function get_json_results($url, $params = [])
 {
     $this->curl->set_option('CURLOPT_FAILONERROR', FALSE);
     $response = $this->curl->get_request($url . '?' . http_build_query($params));
     $result = json_decode($response->get_result(), TRUE);
     if ($response->http_code !== 200) {
         $context = ['message' => $result['message'], 'request' => $url, 'id' => $result['sys']['id']];
         $this->logger->warning('Contentful API Request ({request}) failed with id "{id}": {message}', $context);
         $result['total'] = 0;
     }
     unset($response);
     return $result;
 }
Example #29
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);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function add($key, $data, $ttl)
 {
     if (!$this->enabled) {
         return true;
     }
     try {
         $data = $this->storageFormat($key, $data, $ttl);
         $nKey = $this->key($key);
         $ret = @$this->getConnection()->add($nKey, $data, $ttl);
         $this->Logger->debug("[{$this->persistentId}] " . ($ret ? "Successful" : "Failed to") . " add: '{$key}', Hash: '{$nKey}'");
         return $ret;
     } catch (Exception $e) {
         throw new CacheException($e->getMessage(), $e->getCode());
     }
 }