warn() публичный Метод

This method allows to have an easy ZF compatibility.
public warn ( string $message, array $context = [] ) : boolean
$message string The log message
$context array The log context
Результат boolean Whether the record has been processed
Пример #1
0
 /**
  * Gets a message from RabbitMQ, checks it's a valid transaction and saves it into DB.
  *
  * @param AMQPMessage $rawMessage
  */
 public function process(AMQPMessage $rawMessage)
 {
     $this->logger->debug('Processing message ' . $rawMessage->body);
     try {
         $message = Transaction::extractFromJson($rawMessage->body);
         $message->checkSanity();
         $this->messageDbModel->save($message);
     } catch (Exception $e) {
         // either transaction contains invalid data or there was an error in db
         $this->logger->warn($e->getMessage());
     }
 }
Пример #2
0
 protected function processMessage(QueueMessage $message)
 {
     $msg = null;
     if (isset($message->getBody()->Message)) {
         $msg = json_decode($message->getBody()->Message);
     }
     $this->logger->debug("Processing kill message", ['message' => $msg]);
     if ($msg != null) {
         $jobId = $msg->jobId;
         /** @var Job $job */
         $job = $this->elasticsearch->getJob($jobId);
         if (!is_null($job)) {
             if ($job->getProcess()['host'] == gethostname()) {
                 if ($job->getStatus() == Job::STATUS_WAITING) {
                     $job->setStatus(Job::STATUS_CANCELLED);
                     $job->setResult(['message' => 'Job cancelled by user']);
                     $this->getComponentJobMapper($job->getComponent())->update($job);
                     $this->logger->info("receive-kill: Job '{$jobId}' cancelled", ['job' => $job->getData()]);
                     $this->requeue($job->getId());
                 } else {
                     if ($job->getStatus() == Job::STATUS_PROCESSING) {
                         $job->setStatus(Job::STATUS_TERMINATING);
                         $this->getComponentJobMapper($job->getComponent())->update($job);
                         $pid = $job->getProcess()['pid'];
                         // kill child processes
                         $process = new Process('
                         function getcpid() {
                                     cpids=`pgrep -P $1|xargs`
                             for cpid in $cpids;
                             do
                                 echo "$cpid"
                                 getcpid $cpid
                             done
                         }
                         getcpid ' . $pid);
                         $process->run();
                         $processes = $process->getOutput();
                         if ($processes && count(explode("\n", $processes))) {
                             foreach (explode("\n", $processes) as $child) {
                                 if ($child != '') {
                                     (new Process("sudo kill -KILL {$child}"))->run();
                                 }
                             }
                         }
                         // kill parent process
                         posix_kill($pid, SIGKILL);
                         $this->logger->info("receive-kill: Job '{$jobId}' killed", ['job' => $job->getData()]);
                     } else {
                         $this->logger->info("receive-kill: Job is not in waiting or processing state", ['job' => $job->getData()]);
                     }
                 }
             }
         }
     } else {
         $this->logger->warn("Corrupted message received", ['message' => $message]);
     }
     $this->queue->deleteMessage($message);
 }
 /**
  * @param $message
  * @param $users
  * @param null $extra
  * @return bool|int     Return TRUE if all users get messages, otherwise number of user not received message
  */
 public function send($message, $users, $extra = null, $badge = 0)
 {
     if (!is_array($users)) {
         $users = [$users];
     }
     $sentNum = 0;
     foreach ($users as $user) {
         $devices = $this->pushDeviceService->findDevicesByUser($user);
         $atLeastOneSent = false;
         if (count($devices) > 0) {
             foreach ($devices as $device) {
                 // TODO: save to DB sent notifications
                 if ($device->isiOS()) {
                     if ($this->container->has('push_apns.service')) {
                         $res = $this->container->get('push_apns.service')->push($message, $device, $extra, $badge);
                         $devicesToLog = $device->getDeviceToken();
                         if (true === $res) {
                             $this->logger->info('Message: ' . $message . ', was sent to device#: ' . $devicesToLog, ['PushNotification']);
                             $atLeastOneSent = true;
                         } else {
                             $this->logger->warn('Error occurred while sending message: ' . $message . ', to device#: ' . $devicesToLog, ['PushNotification']);
                         }
                     } else {
                         $this->logger->error('Notification cannot be send as service push_apns.service is not available', ['PushNotification']);
                     }
                 } elseif ($device->isAndroidOS()) {
                     // TODO: TBD
                 }
             }
         } else {
             $this->logger->warn('User #' . $user . ' has no registered devices', ['PushNotification']);
         }
         if ($atLeastOneSent) {
             ++$sentNum;
         }
     }
     if (count($users) == $sentNum) {
         return true;
     } else {
         return count($users) - $sentNum;
     }
 }
Пример #4
0
 /**
  * @param array $parameters
  * @return bool
  */
 public function paymentResponse(array $parameters)
 {
     $paymentResponse = new EcommercePaymentResponse($parameters);
     $passphrase = $this->shaOut;
     $shaComposer = new AllParametersShaComposer($passphrase);
     $shaComposer->addParameterFilter(new ShaOutParameterFilter());
     //optional
     if ($paymentResponse->isValid($shaComposer) && $paymentResponse->isSuccessful()) {
         $event = new OgoneEvent($parameters);
         $this->eventDispatcher->dispatch(OgoneEvents::SUCCESS, $event);
         // handle payment confirmation
         $this->logger->info('Ogone payment success');
         return true;
     } else {
         $event = new OgoneEvent($parameters);
         $this->eventDispatcher->dispatch(OgoneEvents::ERROR, $event);
         $this->logger->warn('Ogone payment failure', $parameters);
     }
     return false;
 }
 private function detectIllegalStateChanges()
 {
     if (null !== $this->aggregateIdentifier && null !== $this->workingAggregate && $this->reportIllegalStateChange) {
         $uow = DefaultUnitOfWork::startAndGet();
         try {
             $aggregate2 = $this->repository->load($this->aggregateIdentifier);
             if ($this->workingAggregate->isDeleted()) {
                 throw new GovernorAssertionError("The working aggregate was considered deleted, " . "but the Repository still contains a non-deleted copy of " . "the aggregate. Make sure the aggregate explicitly marks " . "itself as deleted in an EventHandler.");
             }
             $this->assertValidWorkingAggregateState($aggregate2);
         } catch (AggregateNotFoundException $notFound) {
             if (!$this->workingAggregate->isDeleted()) {
                 throw new GovernorAssertionError("The working aggregate was not considered deleted, " . "but the Repository cannot recover the state of the " . "aggregate, as it is considered deleted there.");
             }
         } catch (\Exception $ex) {
             $this->logger->warn("An Exception occurred while detecting illegal state changes in {class}.", array('class' => get_class($this->workingAggregate)), $ex);
         } finally {
             // rollback to prevent changes bing pushed to event store
             $uow->rollback();
         }
     }
 }
Пример #6
0
 /**
  * Implements failing tables; if an account type fails multiple times,
  * then send the user an email and disable the account.
  * @see OpenclerkJobQueuer#getStandardJobs()
  */
 function failed(\Exception $runtime_exception, Connection $db, Logger $logger)
 {
     // is this a standard job?
     $standard = $this->findStandardJob();
     if ($standard) {
         $logger->info("Using standard job " . print_r($standard, true));
         if (!$standard['failure']) {
             $logger->info("Not a failure standard job");
             return;
         }
     } else {
         return;
     }
     $failing_table = $standard['table'];
     $job = $this->job;
     // find the relevant account_data for this standard job
     $account_data = false;
     foreach (account_data_grouped() as $label => $group) {
         foreach ($group as $exchange => $data) {
             if (isset($data['job_type']) && $job['job_type'] == $data['job_type']) {
                 $account_data = $data;
                 $account_data['exchange'] = $exchange;
                 break;
             }
         }
     }
     if (!$account_data) {
         $logger->warn("Could not find any account data for job type '" . $job['job_type'] . "'");
     }
     $logger->info("Using account data " . print_r($account_data, true));
     // don't count CloudFlare as a failure
     if ($runtime_exception instanceof CloudFlareException || $runtime_exception instanceof \Openclerk\Apis\CloudFlareException) {
         $logger->info("Not increasing failure count: was a CloudFlareException");
     } else {
         if ($runtime_exception instanceof IncapsulaException || $runtime_exception instanceof \Openclerk\Apis\IncapsulaException) {
             $logger->info("Not increasing failure count: was a IncapsulaException");
         } else {
             if ($runtime_exception instanceof BlockchainException || $runtime_exception instanceof \Core\BlockchainException) {
                 $logger->info("Not increasing failure count: was a BlockchainException");
             } else {
                 $q = $db->prepare("UPDATE {$failing_table} SET failures=failures+1,first_failure=IF(ISNULL(first_failure), NOW(), first_failure) WHERE id=?");
                 $q->execute(array($job['arg_id']));
                 $logger->info("Increasing account failure count");
             }
         }
     }
     $user = get_user($job['user_id']);
     if (!$user) {
         $logger->info("Warning: No user " . $job['user_id'] . " found");
     } else {
         // failed too many times?
         $q = $db->prepare("SELECT * FROM {$failing_table} WHERE id=? LIMIT 1");
         $q->execute(array($job['arg_id']));
         $account = $q->fetch();
         $logger->info("Current account failure count: " . number_format($account['failures']));
         if ($account['failures'] >= get_premium_value($user, 'max_failures')) {
             // disable it and send an email
             $q = $db->prepare("UPDATE {$failing_table} SET is_disabled=1 WHERE id=?");
             $q->execute(array($job['arg_id']));
             crypto_log(print_r($account_data, true));
             if ($user['email'] && !$account['is_disabled']) {
                 $email_type = $job['job_type'] == "notification" ? "failure_notification" : "failure";
                 send_user_email($user, $email_type, array("name" => $user['name'] ? $user['name'] : $user['email'], "exchange" => get_exchange_name($account_data['exchange']), "label" => $account_data['label'], "labels" => $account_data['labels'], "failures" => number_format($account['failures']), "message" => $runtime_exception->getMessage(), "length" => recent_format(strtotime($account['first_failure']), "", ""), "title" => isset($account['title']) && $account['title'] ? "\"" . $account['title'] . "\"" : "untitled", "url" => absolute_url(url_for("wizard_accounts"))));
                 $logger->info("Sent failure e-mail to " . htmlspecialchars($user['email']) . ".");
             }
         }
     }
 }
 /**
  * (non-PHPdoc)
  * @see Azine\EmailBundle\Services.NotifierServiceInterface::sendNotifications()
  */
 public function sendNotifications(array &$failedAddresses)
 {
     // get all recipientIds with pending notifications in the database, that are due to be sent
     $recipientIds = $this->getNotificationRecipientIds();
     // get vars that are the same for all recipients of this notification-mail-batch
     $params = $this->getVarsForNotificationsEmail();
     $notificationsTemplate = $this->configParameter[AzineEmailExtension::TEMPLATES . "_" . AzineEmailExtension::NOTIFICATIONS_TEMPLATE];
     foreach ($recipientIds as $recipientId) {
         // send the mail for this recipient
         $failedAddress = $this->sendNotificationsFor($recipientId, $notificationsTemplate, $params);
         if ($failedAddress != null) {
             $failedAddresses[] = $failedAddress;
         }
     }
     // log mail-errors as warnings
     if (sizeof($failedAddresses) > 0) {
         $this->logger->warn("Failed to send message to :\n" . print_r($failedAddresses, true));
     }
     return sizeof($recipientIds) - sizeof($failedAddresses);
 }
Пример #8
0
 /**
  * Adds a log record at the WARNING level.
  *
  * @param string $message The log message
  * @param array $context The log context
  * @return Boolean Whether the record has been processed
  */
 public function warn($message, array $context = array())
 {
     return $this->_logger->warn($message, $context);
 }
 /**
  * Adds a log record at the WARNING level.
  * 
  * This method allows for compatibility with common interfaces.
  *
  * @param string $message The log message
  * @param array $context The log context
  * @return Boolean Whether the record has been processed
  * @static 
  */
 public static function warn($message, $context = array())
 {
     return \Monolog\Logger::warn($message, $context);
 }
Пример #10
0
 /**
  * @param string $message
  * @param array $context
  * @return bool
  */
 public function warn($message, array $context = array())
 {
     return parent::warn($message, $context);
 }
Пример #11
0
 /**
  * @param \Closure|Logger $logger
  * @return void
  */
 public function setLogger($logger)
 {
     if ($logger instanceof Logger) {
         $this->logger = function ($message, $level) use($logger) {
             switch ($level) {
                 case 'info':
                     $logger->info($message);
                     return;
                 case 'warn':
                 default:
                     $logger->warn($message);
                     return;
             }
         };
     } else {
         $this->logger = $logger;
     }
 }
Пример #12
0
 /**
  * Exceptional occurrences that are not errors.
  *
  * Example: Use of deprecated APIs, poor use of an API, undesirable things
  * that are not necessarily wrong.
  *
  * @param string $message
  * @param array  $context
  *
  * @return void
  */
 public function warning($message, array $context = array())
 {
     $this->monolog->warn($message, $context);
 }
Пример #13
0
 /**
  * {@inheritDoc}
  */
 public function warn($msg)
 {
     $this->logger->warn($msg);
 }