Author: Jacob Morrison (email@ofjacob.com)
Inheritance: implements yii\base\BootstrapInterface
Ejemplo n.º 1
0
 /**
  *	Fetches embed information from the given URL.
  *
  *	@param string $url URL to fetch informations from.
  *	@param array $options Custom options to be interpreted by the provider.
  *	@return Media|null Embed informations, or null if nothing could be
  *		fetched.
  */
 public final function embed($url, array $options = [])
 {
     $this->_Preparators->filter($url);
     $Media = $this->_embed($url, $options);
     $Media->setDefault('url', $url);
     return $this->_Presenters->filter($Media);
 }
Ejemplo n.º 2
0
 /**
  * Configure Cascaded Monolog logger and use it.
  *
  * @param        $configFile
  * @param string $loggerName
  */
 private function _initLoggerCascade($configFile, $loggerName)
 {
     $err = '';
     try {
         $fs = $this->_obm->get(Filesystem::class);
         if ($fs->isAbsolutePath($configFile)) {
             $fileName = $configFile;
         } else {
             $fileName = BP . '/' . $configFile;
         }
         $realPath = realpath($fileName);
         if ($realPath) {
             Cascade::fileConfig($realPath);
             $this->_logger = Cascade::getLogger($loggerName);
         } else {
             $err = "Cannot open logging configuration file '{$fileName}'. Default Magento logger is used.";
         }
     } catch (\Exception $e) {
         $err = $e->getMessage();
     } finally {
         if (is_null($this->_logger)) {
             $this->_logger = $this->_obm->get(\Magento\Framework\Logger\Monolog::class);
             $this->warning($err);
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Constructor
  *
  * @param string $loggerName Name of the logger
  * @param array  $loggerOptions Array of logger options
  * @param Monolog\Handler\HandlerInterface[] $handlers Array of Monolog handlers
  * @param callable[] $processors Array of processors
  */
 public function __construct($loggerName, array $loggerOptions = array(), array $handlers = array(), array $processors = array())
 {
     $this->loggerOptions = $loggerOptions;
     $this->handlers = $handlers;
     $this->processors = $processors;
     // This instanciates a Logger object and set it to the Registry
     $this->logger = Cascade::getLogger($loggerName);
 }
Ejemplo n.º 4
0
 public function setNotAllowedHandler()
 {
     $c = $this->slimContainer;
     $c['notAllowedHandler'] = function ($c) {
         return function ($request, $response, $methods) use($c) {
             Cascade::getLogger('app')->error("Method not allow. {$methods}, " . $request->getUri());
             $res = ['error' => ['code' => -32601, 'message' => 'Method not found']];
             return $c['response']->withHeader('Allow', implode(', ', $methods))->withJson($res, 405);
         };
     };
 }
Ejemplo n.º 5
0
 public function validation($ruleName, $value)
 {
     Cascade::getLogger('bigc\\profile')->debug("ProfileData validation {$ruleName}, {$value}");
     try {
         $this->validRule[$ruleName]->assert($value);
     } catch (\Respect\Validation\Exceptions\NestedValidationException $ex) {
         $e = new \InvalidArgumentException($this->validMessage[$ruleName], 0, $ex);
         Cascade::getLogger('bigc\\profile')->warning($e->getMessage());
         throw $e;
     }
     return true;
 }
Ejemplo n.º 6
0
 /**
  * Create an object
  *
  * @param  ContainerInterface $container
  * @param  string $requestedName
  * @param  null|array $options
  * @return object
  * @throws ServiceNotFoundException if unable to resolve the service.
  * @throws ServiceNotCreatedException if an exception is raised when
  *     creating a service.
  * @throws ContainerException if any other error occurs
  */
 public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
 {
     $config = $container->has('config') ? $container->get('config') : [];
     Cascade::fileConfig(isset($config['logger']) ? $config['logger'] : ['loggers' => []]);
     // Compose requested logger name
     $loggerName = isset($options) & isset($options['logger_name']) ? $options['logger_name'] : 'Logger';
     $nameParts = explode('_', $requestedName);
     if (count($nameParts) > 1) {
         $loggerName = $nameParts[1];
     }
     return Cascade::getLogger($loggerName);
 }
 /**
  * Load a configuration for the loggers from `.settings.php` or `.settings_extra.php`.
  *
  * @param bool $force Load even if the configuration has already been loaded.
  *
  * @return bool
  */
 public static function loadConfiguration($force = false)
 {
     if ($force === false && static::$isConfigurationLoaded === true) {
         return true;
     }
     if (class_exists('\\Bitrix\\Main\\Config\\Configuration')) {
         $config = Configuration::getInstance()->get('monolog');
         if (is_array($config) && !empty($config)) {
             Cascade::fileConfig($config);
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 8
0
 /**
  * Logs with an arbitrary level.
  *
  * @param mixed $level
  * @param string $message
  * @param mixed $context
  * @return null
  */
 public static function log($level, $message, $context = null)
 {
     // on this place we can allow create unique indexes for the platform of Kibana
     if (is_array($context) && array_key_exists('exception', $context) && $context['exception'] instanceof \Exception) {
         $e = $context['exception'];
         unset($context['exception']);
         $context = ['value' => $context];
         $context['code'] = $e->getCode();
         $context['class'] = get_class($e);
         if (is_string($message)) {
             $message = trim($message . ' ' . $e->getMessage());
         }
     } else {
         $context = ['value' => $context];
         if ($message instanceof \Exception) {
             $e = $message;
             $message = $e->getMessage();
             $context['code'] = $e->getCode();
             $context['class'] = get_class($e);
         } else {
             $e = new DebugException();
         }
     }
     if ($e instanceof DebugException) {
         // set real values of fields File and Line (if they will found)
         $placeTheCall = self::getInfoTheCall($e);
         $context['trace'] = self::getRealTraceString($e, $placeTheCall);
         if ($e->getExtra()) {
             $context['extra'] = $e->getExtra();
         }
     } else {
         $context['trace'] = $e->getTraceAsString();
     }
     // Exception of lambda function not have this methods
     if ($e->getFile()) {
         $context['file'] = $e->getFile();
     }
     if ($e->getLine()) {
         $context['line'] = $e->getLine();
     }
     if (class_exists('TC\\Logger\\LoggerProfiler')) {
         $loggerProfiler = \TC\Logger\LoggerProfiler::getInstance();
         $context['requestId'] = $loggerProfiler->getRequestId();
         $context['subrequestId'] = $loggerProfiler->getSubrequestId();
     }
     if (class_exists('TC\\Logger\\CurrentRequestHelper')) {
         $context['requestAsCurl'] = (new \TC\Logger\CurrentRequestHelper())->getRequestAsCurl();
     }
     if (class_exists('GuzzleHttp\\Post\\PostBody') && (class_exists('GuzzleHttp\\Exception\\RequestException') && $e instanceof \GuzzleHttp\Exception\RequestException) || class_exists('GuzzleHttp\\Exception\\ConnectException') && $e instanceof \GuzzleHttp\Exception\ConnectException) {
         $request = $e->getRequest();
         $body = $request->getBody();
         if ($body instanceof \GuzzleHttp\Post\PostBody && ($fields = $body->getFields())) {
             // find bad provider
             if (!empty($fields['providers'][0])) {
                 $context['providerId'] = (int) $fields['providers'][0];
             }
         }
         $headers = [];
         foreach ($request->getHeaders() as $name => $values) {
             $headers[] = $name . ':' . implode(', ', $values);
         }
         $context['guzzleRequest'] = ['host' => $request->getHost(), 'url' => $request->getUrl(), 'method' => $request->getMethod(), 'config' => $request->getConfig(), 'headers' => implode('; ', $headers)];
         if (interface_exists('GuzzleHttp\\Message\\MessageInterface') && $e->getResponse() instanceof \GuzzleHttp\Message\MessageInterface) {
             $context['guzzleRequest']['response'] = mb_substr($e->getResponse()->getBody(), 0, self::MAX_LENGTH_BAD_RESPONSE);
         }
     }
     $message = self::export($message);
     $context = self::getCachedContextDump($level, $message, $context);
     Cascade::getLogger('mainLogger')->log($level, $message, $context);
 }
Ejemplo n.º 9
0
<?php

require_once realpath(__DIR__ . '/../vendor/autoload.php');
use Cascade\Cascade;
$logger = Cascade::getLogger('some_logger');
$logger->pushHandler(new Monolog\Handler\StreamHandler('php://stdout'));
$logger->info('Hellooooo World!');
// you should see the follwing in the stdout:
//    [YYYY-mm-dd hh:mm:ss] some_logger.INFO: Hellooooo World!
Ejemplo n.º 10
0
<?php

/**
 * @link https://github.com/bitrix-expert/monolog-adapter
 * @copyright Copyright © 2015 Nik Samokhvalov
 * @license MIT
 */
use Bitrix\Main\Config\Configuration;
use Cascade\Cascade;
if (class_exists('\\Bitrix\\Main\\Config\\Configuration')) {
    $config = Configuration::getInstance()->get('monolog');
    if (is_array($config) && !empty($config)) {
        Cascade::fileConfig($config);
    }
}
<?php

require_once realpath(__DIR__ . '/../vendor/autoload.php');
use Cascade\Cascade;
$loggerConfigFile = realpath(__DIR__ . '/logger_config.yml');
// you can use json too!
// $loggerConfigFile = realpath(__DIR__.'/logger_config.json');
Cascade::fileConfig($loggerConfigFile);
Cascade::getLogger('loggerA')->info('Well, that works!');
Cascade::getLogger('loggerB')->error('Maybe not...');
// This should log into 2 different log files depending on the level: 'example_info.log' and 'example_error.log'
<?php

require_once realpath(__DIR__ . '/../vendor/autoload.php');
use Cascade\Cascade;
// For these to work you will need php-redis and raven/raven
// You will want to update this file with a valid dsn
$loggerConfigFile = realpath(__DIR__ . '/dependency_config.yml');
Cascade::fileConfig($loggerConfigFile);
Cascade::getLogger('dependency')->info('Well, that works!');
Cascade::getLogger('dependency')->error('Maybe not...');
Ejemplo n.º 13
0
 /**
  * General  method to write out logs.
  *
  * @param mixed  $level
  * @param string $message
  * @param array  $context
  */
 public function log($level, $message, array $context = [])
 {
     if (!$this->_isMonologUsed) {
         /* prepare log message for Magento default log */
         if (is_array($context) && count($context)) {
             $msg = $this->_loggerName . ': ' . $message . ' [' . str_replace("\n", ' ', var_export($context, true)) . ']';
         } else {
             $msg = $this->_loggerName . ': ' . $message;
         }
         $zendLevel = $this->_getZendLevel($level);
         \Mage::log($msg, $zendLevel);
     } else {
         Cascade::getLogger($this->_loggerName)->log($level, $message, $context);
     }
 }
Ejemplo n.º 14
0
Archivo: Log.php Proyecto: yapro/debug
 /**
  * Logs with an arbitrary level.
  *
  * @param mixed $level
  * @param string $message
  * @param mixed $context
  * @return null
  */
 private static function log($level, $message, $context = null)
 {
     // on this place we can allow create unique indexes for the platform of Kibana
     $context = ['value' => $context];
     if ($message instanceof \Exception) {
         $e = $message;
         $message = $e->getMessage();
         $context['code'] = $e->getCode();
         $context['class'] = get_class($e);
     } else {
         $e = new DebugException();
     }
     if ($e instanceof DebugException) {
         // set real values of fields File and Line (if they will found)
         $placeTheCall = self::getInfoTheCall($e);
         $context['trace'] = self::getRealTraceString($e, $placeTheCall);
         if ($e->getExtra()) {
             $context['extra'] = $e->getExtra();
         }
     } else {
         $context['trace'] = $e->getTraceAsString();
     }
     // Exception of lambda function not have this methods
     if ($e->getFile()) {
         $context['file'] = $e->getFile();
     }
     if ($e->getLine()) {
         $context['line'] = $e->getLine();
     }
     if (class_exists('TC\\Logger\\LoggerProfiler')) {
         $loggerProfiler = \TC\Logger\LoggerProfiler::getInstance();
         $context['requestId'] = $loggerProfiler->getRequestId();
         $context['subrequestId'] = $loggerProfiler->getSubrequestId();
     }
     if (class_exists('TC\\Logger\\CurrentRequestHelper')) {
         $context['requestAsCurl'] = (new \TC\Logger\CurrentRequestHelper())->getRequestAsCurl();
     }
     if (class_exists('GuzzleHttp\\Exception\\RequestException') && class_exists('GuzzleHttp\\Post\\PostBody') && $e instanceof \GuzzleHttp\Exception\RequestException) {
         $request = $e->getRequest();
         $body = $request->getBody();
         if ($body instanceof \GuzzleHttp\Post\PostBody && ($fields = $body->getFields())) {
             // find bad provider
             if (!empty($fields['providers'][0])) {
                 $context['providerId'] = (int) $fields['providers'][0];
             }
         }
         $headers = [];
         foreach ($request->getHeaders() as $name => $values) {
             $headers[$name] = implode(', ', $values);
         }
         $context['guzzleRequest'] = ['url' => $request->getUrl(), 'method' => $request->getMethod(), 'config' => $request->getConfig(), 'headers' => implode(': ', $headers)];
     }
     Cascade::getLogger('mainLogger')->log($level, self::export($message), self::dumpContext($context));
 }
Ejemplo n.º 15
0
 public function testFileConfig()
 {
     $options = Fixtures::getPhpArrayConfig();
     Cascade::fileConfig($options);
     $this->assertInstanceOf('Cascade\\Config', Cascade::getConfig());
 }