/** * @param mixed $level * @param string $message * @param array $context * @return null * @throws PsrInvalidArgumentException */ public function log($level, $message, array $context = array()) { switch ($level) { case PsrLogLevel::ALERT: $this->symfonyLogger->alert($message, $context); break; case PsrLogLevel::CRITICAL: $this->symfonyLogger->crit($message, $context); break; case PsrLogLevel::DEBUG: $this->symfonyLogger->debug($message, $context); break; case PsrLogLevel::EMERGENCY: $this->symfonyLogger->emerg($message, $context); break; case PsrLogLevel::ERROR: $this->symfonyLogger->err($message, $context); break; case PsrLogLevel::INFO: $this->symfonyLogger->info($message, $context); break; case PsrLogLevel::NOTICE: $this->symfonyLogger->notice($message, $context); break; case PsrLogLevel::WARNING: $this->symfonyLogger->warn($message, $context); break; default: throw new PsrInvalidArgumentException(sprintf('Loglevel "%s" not valid, use constants from "%s"', $level, "Psr\\Log\\LogLevel")); break; } return null; }
/** * Log a resource unsubscription attempt. * @param boolean $successful Whether the attempt succeeded. * @param array $url The resource URLs. */ public function logUnsubscribeAttempt($successful, array $urls) { // Write the actual logs foreach ($urls as $url) { if ($successful) { $this->logger->info(sprintf('Unsubscribed from resource "%s"', $url)); } else { $this->logger->warn(sprintf('Unsuccessful unsubscription attempt from resource "%s"', $url)); } } // Store the data directly $this->unsubscribeAttempts[] = new UnsubscribeAttempt($successful, $urls); }
/** * {@inheritdoc} */ public function listen() { $this->xmpp->connectAndStartSession($this->timeout); // Add the message handler $this->xmpp->addXPathHandler('{jabber:client}message/{http://jabber.org/protocol/pubsub#event}event/{http://superfeedr.com/xmpp-pubsub-ext}status', 'handleMessage', $this); // Process messages repeatedly while (!$this->xmpp->isDisconnected()) { $results = $this->xmpp->processUntil('message', $this->timeout); if (count($results) === 0) { $this->logger->warn(sprintf('Superfeedr listener timed out (no messages for %d seconds).', $this->timeout)); throw new Exception\TimeoutException(sprintf('No messages for %d seconds. The connection may have been lost.', $this->timeout)); } } }
/** * Returns true if Akismet believes the data is a spam * * @param array data only the model data. The request data is added automatically. * Exemple: * array( * 'comment_author' => 'Jack', * 'comment_content' => 'The moon core is made of cheese' * ) * * @return bool true if it is spam */ public function isSpam(array $data) { $fullData = array_merge($this->getRequestData(), $data); if ($this->throwExceptions) { return $this->adapter->isSpam($fullData); } try { return $this->adapter->isSpam($fullData); } catch (\Exception $e) { if ($this->logger) { $this->logger->warn(sprintf('%s: %s(%s)', get_class($this), get_class($e), $e->getMessage())); } return false; } }
/** * Saves a Profile. * * @param Profile $profile A Profile instance * * @return Boolean */ public function saveProfile(Profile $profile) { if (!($ret = $this->storage->write($profile)) && null !== $this->logger) { $this->logger->warn('Unable to store the profiler information.'); } return $ret; }
/** * @throws \ErrorException When error_reporting returns error */ public function handle($level, $message, $file, $line, $context) { if (0 === $this->level) { return false; } if ($level & (E_USER_DEPRECATED | E_DEPRECATED)) { if (null !== self::$logger) { $deprecation = array('type' => self::TYPE_DEPRECATION, 'file' => $file, 'line' => $line, 'stack' => version_compare(PHP_VERSION, '5.4', '<') ? array_slice(debug_backtrace(false), 0, 10) : debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 10)); self::$logger->warn($message, $deprecation); } return true; } if (error_reporting() & $level && $this->level & $level) { throw new \ErrorException(sprintf('%s: %s in %s line %d', isset($this->levels[$level]) ? $this->levels[$level] : $level, $message, $file, $line), 0, $level, $file, $line); } return false; }
/** * Executes the block as specified in the content. * * @param array $block An array including the block name * * @return string the rendered block */ protected function embeddedRender($block) { try { return $this->sonataBlock->render(array('name' => trim($block[1]))); } catch (\Exception $e) { if ($this->logger) { $this->logger->warn('Failed to render block "' . $block[1] . '" embedded in content: ' . $e->getTraceAsString()); } } return ''; }
/** * {@inheritDoc} */ public function execute(AMQPMessage $msg) { if ($this->logger) { $this->logger->info('[GithubHookConsumer] Received a github post push hook'); } if (null === ($message = json_decode($msg->body))) { if ($this->logger) { $this->logger->err('[GithubHookConsumer] Unable to decode payload'); } return; } $payload = $message->payload; $bundle = $this->manager->getRepository('KnpBundlesBundle:Bundle')->findOneBy(array('name' => $payload->repository->name, 'ownerName' => $payload->repository->owner->name)); if (!$bundle) { if ($this->logger) { $this->logger->warn(sprintf('[GithubHookConsumer] unknown bundle %s/%s', $payload->repository->name, $payload->repository->owner->name)); } return; } $this->producer->publish(serialize(array('bundle_id' => $bundle->getId()))); }
/** * {@inheritDoc} */ public function store(Response $response, $targetPath, $filter) { $storageResponse = $this->storage->create_object($this->bucket, $targetPath, array('body' => $response->getContent(), 'contentType' => $response->headers->get('Content-Type'), 'length' => strlen($response->getContent()), 'acl' => $this->acl)); if ($storageResponse->isOK()) { $response->setStatusCode(301); $response->headers->set('Location', $this->getObjectUrl($targetPath)); } else { if ($this->logger) { $this->logger->warn('The object could not be created on Amazon S3.', array('targetPath' => $targetPath, 'filter' => $filter, 's3_response' => $storageResponse)); } } return $response; }
/** * {@inheritDoc} */ public function store(Response $response, $targetPath, $filter) { try { $storageResponse = $this->storage->putObject(array('ACL' => $this->acl, 'Bucket' => $this->bucket, 'Key' => $targetPath, 'Body' => $response->getContent(), 'ContentType' => $response->headers->get('Content-Type'))); } catch (\Exception $e) { if ($this->logger) { $this->logger->warn('The object could not be created on Amazon S3.', array('targetPath' => $targetPath, 'filter' => $filter)); } return $response; } $response->setStatusCode(301); $response->headers->set('Location', $storageResponse->get('ObjectURL')); return $response; }
/** * Removes a specified bundle * * @param Bundle $bundle */ protected function removeBundle(Bundle $bundle) { $owner = $bundle->getOwner(); if ($owner instanceof Owner) { $owner->removeBundle($bundle); } // remove bundle from search index $this->indexer->deleteBundlesIndexes($bundle); $this->em->remove($bundle); $this->em->flush(); // @todo also delete folder if ($this->logger) { $this->logger->warn(sprintf('Bundle "%s" was deleted', $bundle->getName())); } }
/** * A convenience function for logging a warning event. * * @param mixed $message the message to log. */ public function warning($message) { if (null !== $this->logger) { $this->logger->warn($message); } }
/** * A convenience function for logging a warning event. * * @param mixed $message the message to log. */ public function warning($message) { $this->logger->warn($message); }