public function __construct($name = 'PHPUnit', $level = 'debug')
 {
     /**
      * Filter growl notifications and send only
      * - test failures ($handerLevel = Logger::NOTICE; see GrowlHandler constructor)
      * - summary of test suites (message "Results OK ...", or "Results KO ..."
      */
     $filters = array(function ($record, $handlerLevel) {
         if ($record['level'] > $handlerLevel) {
             return true;
         }
         return preg_match('/^Results/', $record['message']) === 1;
     });
     $stream = new RotatingFileHandler(__DIR__ . DIRECTORY_SEPARATOR . 'monologTestListener.log', 0, Logger::toMonologLevel($level));
     $stream->setFilenameFormat('{filename}-{date}', 'Ymd');
     $handlers = array($stream);
     try {
         // be notified only for test suites and test failures
         $growl = new GrowlHandler(array(), Logger::NOTICE);
         $handlers[] = new CallbackFilterHandler($growl, $filters);
     } catch (\Exception $e) {
         // Growl server is probably not started
         echo $e->getMessage(), PHP_EOL, PHP_EOL;
     }
     parent::__construct($name, $handlers);
 }
Пример #2
0
 public function __construct($level = Logger::DEBUG, array $skipClassesPartials = array(), array $skipFunctions = array(), $skipStackFramesCount = 0)
 {
     $this->level = Logger::toMonologLevel($level);
     $this->skipClassesPartials = array_merge(array('Monolog\\'), $skipClassesPartials);
     $this->skipFunctions = array_merge($this->skipFunctions, $skipFunctions);
     $this->skipStackFramesCount = $skipStackFramesCount;
 }
Пример #3
0
 /**
  * @param HandlerInterface $handler            Handler.
  * @param string           $deduplicationStore The file/path where the deduplication log should be kept
  * @param int              $deduplicationLevel The minimum logging level for log records to be looked at for deduplication purposes
  * @param int              $time               The period (in seconds) during which duplicate entries should be suppressed after a given log is sent through
  * @param Boolean          $bubble             Whether the messages that are handled can bubble up the stack or not
  */
 public function __construct(HandlerInterface $handler, $deduplicationStore = null, $deduplicationLevel = Logger::ERROR, $time = 60, $bubble = true)
 {
     parent::__construct($handler, 0, Logger::DEBUG, $bubble, false);
     $this->deduplicationStore = $deduplicationStore === null ? sys_get_temp_dir() . '/monolog-dedup-' . substr(md5(__FILE__), 0, 20) . '.log' : $deduplicationStore;
     $this->deduplicationLevel = Logger::toMonologLevel($deduplicationLevel);
     $this->time = $time;
 }
Пример #4
0
 public function register(Application $app)
 {
     // System log
     $app['logger.system'] = $app->share(function ($app) {
         $log = new Logger('logger.system');
         $log->pushHandler($app['monolog.handler']);
         $log->pushHandler(new SystemHandler($app, Logger::INFO));
         return $log;
     });
     // Changelog
     $app['logger.change'] = $app->share(function ($app) {
         $log = new Logger('logger.change');
         $log->pushHandler(new RecordChangeHandler($app));
         return $log;
     });
     // Firebug
     $app['logger.firebug'] = $app->share(function ($app) {
         $log = new Logger('logger.firebug');
         $handler = new FirePHPHandler();
         $handler->setFormatter(new WildfireFormatter());
         $log->pushHandler($handler);
         return $log;
     });
     // System log
     $app['logger.flash'] = $app->share(function ($app) {
         $log = new FlashLogger();
         return $log;
     });
     // Manager
     $app['logger.manager'] = $app->share(function ($app) {
         $changeRepository = $app['storage']->getRepository('Bolt\\Storage\\Entity\\LogChange');
         $systemRepository = $app['storage']->getRepository('Bolt\\Storage\\Entity\\LogSystem');
         $mgr = new Manager($app, $changeRepository, $systemRepository);
         return $mgr;
     });
     $app->register(new MonologServiceProvider(), ['monolog.name' => 'bolt']);
     $app['monolog.level'] = function ($app) {
         return Logger::toMonologLevel($app['config']->get('general/debuglog/level'));
     };
     $app['monolog.logfile'] = function ($app) {
         return $app['resources']->getPath('cache') . '/' . $app['config']->get('general/debuglog/filename');
     };
     $app['monolog.handler'] = $app->extend('monolog.handler', function ($handler, $app) {
         // If we're not debugging, just send to /dev/null
         if (!$app['config']->get('general/debuglog/enabled')) {
             return new NullHandler();
         }
         return $handler;
     });
     // If we're not debugging, just send to /dev/null
     if (!$app['config']->get('general/debuglog/enabled')) {
         $app['monolog.handler'] = function () {
             return new NullHandler();
         };
     }
     $app['logger.debug'] = function () use($app) {
         return $app['monolog'];
     };
 }
Пример #5
0
 /**
  * Get log level.
  *
  * @return int
  *
  * @author Wuhsien Yu <*****@*****.**>
  *
  * @since  2016/03/12
  */
 protected static function getLevel()
 {
     $level = Logger::toMonologLevel(Config::get('log.level'));
     if (!in_array($level, Logger::getLevels())) {
         $level = Logger::INFO;
     }
     return $level;
 }
Пример #6
0
 /**
  * @covers Monolog\Logger::toMonologLevel
  */
 public function testConvertPSR3ToMonologLevel()
 {
     $this->assertEquals(Logger::toMonologLevel('debug'), 100);
     $this->assertEquals(Logger::toMonologLevel('info'), 200);
     $this->assertEquals(Logger::toMonologLevel('notice'), 250);
     $this->assertEquals(Logger::toMonologLevel('warning'), 300);
     $this->assertEquals(Logger::toMonologLevel('error'), 400);
     $this->assertEquals(Logger::toMonologLevel('critical'), 500);
     $this->assertEquals(Logger::toMonologLevel('alert'), 550);
     $this->assertEquals(Logger::toMonologLevel('emergency'), 600);
 }
 public static function factory(array $config, array $handlers, $debug)
 {
     $config = self::validateAndNormaliseConfig($config);
     if (!isset($handlers[$config['handler']])) {
         throw new InvalidConfigurationException(sprintf("No handler with name '%s' defined. Did you define it before this handler?", $config['handler']));
     }
     if ($debug) {
         // When debug is enabled, do not buffer messages, but let them be handled our delegate handler.
         return $handlers[$config['handler']];
     }
     return new FingersCrossedHandler($handlers[$config['handler']], $config['activation_strategy']['factory']::factory($config['activation_strategy']['conf']), 0, true, true, Logger::toMonologLevel($config['passthru_level']));
 }
 /**
  * @param string       $token             Pushover api token
  * @param string|array $users             Pushover user id or array of ids the message will be sent to
  * @param string       $title             Title sent to the Pushover API
  * @param integer      $level             The minimum logging level at which this handler will be triggered
  * @param Boolean      $bubble            Whether the messages that are handled can bubble up the stack or not
  * @param Boolean      $useSSL            Whether to connect via SSL. Required when pushing messages to users that are not
  *                                        the pushover.net app owner. OpenSSL is required for this option.
  * @param integer      $highPriorityLevel The minimum logging level at which this handler will start
  *                                        sending "high priority" requests to the Pushover API
  * @param integer      $emergencyLevel    The minimum logging level at which this handler will start
  *                                        sending "emergency" requests to the Pushover API
  * @param integer      $retry             The retry parameter specifies how often (in seconds) the Pushover servers will send the same notification to the user.
  * @param integer      $expire            The expire parameter specifies how many seconds your notification will continue to be retried for (every retry seconds).
  */
 public function __construct($token, $users, $title = null, $level = Logger::CRITICAL, $bubble = true, $useSSL = true, $highPriorityLevel = Logger::CRITICAL, $emergencyLevel = Logger::EMERGENCY, $retry = 30, $expire = 25200)
 {
     $connectionString = $useSSL ? 'ssl://api.pushover.net:443' : 'api.pushover.net:80';
     parent::__construct($connectionString, $level, $bubble);
     $this->token = $token;
     $this->users = (array) $users;
     $this->title = $title ?: gethostname();
     $this->highPriorityLevel = Logger::toMonologLevel($highPriorityLevel);
     $this->emergencyLevel = Logger::toMonologLevel($emergencyLevel);
     $this->retry = $retry;
     $this->expire = $expire;
 }
 /**
  * {@inheritdoc}
  */
 public function load(array $configs, ContainerBuilder $container)
 {
     $configuration = new Configuration();
     $config = $this->processConfiguration($configuration, $configs);
     // Converts PSR-3 levels to Monolog ones if necessary
     $config['level'] = Logger::toMonologLevel($config['level']);
     $container->setParameter('ae_monolog_fluentd.host', $config['host']);
     $container->setParameter('ae_monolog_fluentd.port', $config['port']);
     $container->setParameter('ae_monolog_fluentd.options', $config['options']);
     $container->setParameter('ae_monolog_fluentd.level', $config['level']);
     $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
     $loader->load('services.xml');
 }
Пример #10
0
 /**
  *
  * @param int|array $minLevelOrList
  *        	A list of levels to accept or a minimum level if maxLevel is provided
  * @param int $maxLevel
  *        	Maximum level to accept, only used if $minLevelOrList is not an array
  */
 public function setAcceptedLevels($minLevelOrList = Logger::DEBUG, $maxLevel = Logger::EMERGENCY)
 {
     if (is_array($minLevelOrList)) {
         $acceptedLevels = array_map('Monolog\\Logger::toMonologLevel', $minLevelOrList);
     } else {
         $minLevelOrList = Logger::toMonologLevel($minLevelOrList);
         $maxLevel = Logger::toMonologLevel($maxLevel);
         $acceptedLevels = array_values(array_filter(Logger::getLevels(), function ($level) use($minLevelOrList, $maxLevel) {
             return $level >= $minLevelOrList && $level <= $maxLevel;
         }));
     }
     $this->acceptedLevels = array_flip($acceptedLevels);
 }
Пример #11
0
 public function register(App $glue)
 {
     #if (!$glue->config->exists('monolog.path')) {
     #    // No log path set
     #    return;
     #}
     $glue->singleton('Monolog\\Logger', function ($glue) {
         $logLevel = $glue->config->get('monolog.level', Logger::ERROR);
         $logLevel = Logger::toMonologLevel($logLevel);
         $folder = $glue->config->get('monolog.folder');
         $filename = $glue->config->get('monolog.file', 'app.log');
         // create a log channel
         $log = new Logger($glue->config->get('monolog.name', 'glue'));
         $log->pushHandler(new StreamHandler($folder . '/' . $filename, $logLevel));
         return $log;
     });
     $glue->singleton('Psr\\Log\\LoggerInterface', 'Monolog\\Logger');
     $glue->alias('Monolog\\Logger', 'log');
 }
Пример #12
0
 /**
  * @param callable|HandlerInterface       $handler            Handler or factory callable($record, $fingersCrossedHandler).
  * @param int|ActivationStrategyInterface $activationStrategy Strategy which determines when this handler takes action
  * @param int                             $bufferSize         How many entries should be buffered at most, beyond that the oldest items are removed from the buffer.
  * @param Boolean                         $bubble             Whether the messages that are handled can bubble up the stack or not
  * @param Boolean                         $stopBuffering      Whether the handler should stop buffering after being triggered (default true)
  * @param int                             $passthruLevel      Minimum level to always flush to handler on close, even if strategy not triggered
  */
 public function __construct($handler, $activationStrategy = null, $bufferSize = 0, $bubble = true, $stopBuffering = true, $passthruLevel = null)
 {
     if (null === $activationStrategy) {
         $activationStrategy = new ErrorLevelActivationStrategy(Logger::WARNING);
     }
     // convert simple int activationStrategy to an object
     if (!$activationStrategy instanceof ActivationStrategyInterface) {
         $activationStrategy = new ErrorLevelActivationStrategy($activationStrategy);
     }
     $this->handler = $handler;
     $this->activationStrategy = $activationStrategy;
     $this->bufferSize = $bufferSize;
     $this->bubble = $bubble;
     $this->stopBuffering = $stopBuffering;
     if ($passthruLevel !== null) {
         $this->passthruLevel = Logger::toMonologLevel($passthruLevel);
     }
     if (!$this->handler instanceof HandlerInterface && !is_callable($this->handler)) {
         throw new \RuntimeException("The given handler (" . json_encode($this->handler) . ") is not a callable nor a Monolog\\Handler\\HandlerInterface object");
     }
 }
 public function __construct($actionLevel, array $ignore)
 {
     $this->actionLevel = \Monolog\Logger::toMonologLevel($actionLevel);
     $this->ignore = $ignore;
 }
Пример #14
0
 public function __construct($level = Logger::DEBUG, $backtraceLevel = 8)
 {
     $this->level = Logger::toMonologLevel($level);
     $this->backtraceLevel = $backtraceLevel;
 }
Пример #15
0
 /**
  * Register a rotating file log handler.
  *
  * @param  string  $level
  * @param  string  $path
  * @return void
  */
 public function useRotatingFiles($level = 'debug', $path = null)
 {
     $path || ($path = $this->settings['directory']);
     $this->monolog->pushHandler($handler = new Handler\RotatingFileHandler($path, 5, Logger::toMonologLevel($level)));
     $handler->setFormatter($this->getDefaultFormatter());
     return $this;
 }
 public function __construct($level = Logger::DEBUG, array $skipClassesPartials = array('Monolog\\'))
 {
     $this->level = Logger::toMonologLevel($level);
     $this->skipClassesPartials = $skipClassesPartials;
 }
Пример #17
0
 /**
  * Init the Logger
  */
 protected function initLogger()
 {
     $this->logger = new Logger(__CLASS__);
     $log_level = Logger::INFO;
     if (isset($this->config['log_level']) && !empty($this->config['log_level'])) {
         $log_level = Logger::toMonologLevel($this->config['log_level']);
     }
     if (isset($this->config['log_file'])) {
         $handler = new StreamHandler($this->config['log_file'], $log_level);
         $this->logger->pushHandler($handler);
     }
 }
Пример #18
0
//
//  Logger initialization
//
//------------------------------------------------------------------------------
/*! Note @ 7 Aug, 2015
 *  Here we started to make use of the Psr\Log interface and Seldaek\Monolog,
 *  digging the original Log class empty as a wrapper to LoggerInterface, and
 *  moved the backtrace and session info into separate processors in monolog.
 *
 *  Specifically, backtrace context like file, subject and action are moved to
 *  the BacktraceProcessor class, while session info is moved to the
 *  SessionProcessor class.
 *
 *  Node::set() invoke is migrated into NodeHandler class.
 */
Log::setLogger(new Logger('default'));
// Log enabled
if (conf::get('system::log.enabled', true)) {
    $level = Logger::toMonologLevel(conf::get('system::log.level', 'debug'));
    Log::getLogger()->pushProcessor(new BacktraceProcessor($level))->pushProcessor(new SessionProcessor($level))->pushProcessor(new ProcessProcessor($level))->pushHandler(new NodeHandler($level));
    unset($level);
} else {
    // This should not be necessary, no handlers will run nothing.
    Log::getLogger()->pushHandler(new NullHandler());
}
//------------------------------------------------------------------------------
//
//  System shims
//
//------------------------------------------------------------------------------
require_once __DIR__ . '/framework/environment.php';
Пример #19
0
 public function __construct($level = Logger::DEBUG)
 {
     $this->level = Logger::toMonologLevel($level);
 }
Пример #20
0
 /**
  * Sets minimum logging level at which this handler will be triggered.
  *
  * @param  int  $level
  * @return self
  */
 public function setLevel($level)
 {
     $this->level = Logger::toMonologLevel($level);
     return $this;
 }
Пример #21
0
    $path = $settings['view']['template_path'] ?? '../templates';
    $twig_settings = $settings['view']['twig'] ?? $default_config;
    // Create Twig object and add Slim extensions
    $view = new \Slim\Views\Twig($path, $twig_settings);
    $view->addExtension(new Slim\Views\TwigExtension($c->router, $c->request->getUri()));
    $view->addExtension(new Twig_Extension_Debug());
    return $view;
};
// Monolog logging service: https://github.com/Seldaek/monolog
$container['logger'] = function ($c) use($settings) {
    $name = $settings['logger']['name'] ?? __FILE__;
    $location = $settings['logger']['path'] ?? '../logs/application.log';
    $log_level = $settings['logger']['level'] ?? 'DEBUG';
    $logger = new \Monolog\Logger($name);
    $logger->pushProcessor(new \Monolog\Processor\UidProcessor());
    $logger->pushHandler(new \Monolog\Handler\StreamHandler($location, \Monolog\Logger::toMonologLevel($log_level)));
    return $logger;
};
/**
 * -----------------------------------------------------------------------------
 * Service Layer
 * -----------------------------------------------------------------------------
 *
 * These classes provide the business logic to interact with services and build the information necessary for
 * views.  View routes.php to see how these classes are mapped to URLs
 */
$container['myService'] = function ($c) {
    return new \USF\IdM\SlimSkeleton\Service\ExampleService($c->logger, $c->settings);
};
/**
 * -----------------------------------------------------------------------------
 /**
  * @param int   $defaultActionLevel   The default action level to be used if the record's category doesn't match any
  * @param array $channelToActionLevel An array that maps channel names to action levels.
  */
 public function __construct($defaultActionLevel, $channelToActionLevel = array())
 {
     $this->defaultActionLevel = Logger::toMonologLevel($defaultActionLevel);
     $this->channelToActionLevel = array_map('Monolog\\Logger::toMonologLevel', $channelToActionLevel);
 }
Пример #23
0
 /**
  * Converts PSR-3 levels to Monolog ones if necessary
  *
  * @param string|int  Level number (monolog) or name (PSR-3)
  * @return int 
  * @static 
  */
 public static function toMonologLevel($level)
 {
     return \Monolog\Logger::toMonologLevel($level);
 }
Пример #24
0
 public function __construct($actionLevel)
 {
     $this->actionLevel = Logger::toMonologLevel($actionLevel);
 }
Пример #25
0
 public function build(ContainerBuilder $builder)
 {
     $builder->bind(LoggerInterface::class)->scoped(new Singleton())->to(function (TestSystem $system) {
         $handler = new ErrorLogHandler(ErrorLogHandler::SAPI, Logger::toMonologLevel(strtolower($system->getLogLevel())));
         $handler->pushProcessor(new PsrLogMessageProcessor());
         $monolog = new Logger('System');
         $monolog->pushHandler($handler);
         return $monolog;
     });
 }