コード例 #1
0
 /**
  * Helper method to register log handlers a to the given
  * Logger instance according to config
  */
 protected static function addHandlers($logger, $name)
 {
     $handlers = 0;
     $config = Config::getInstance();
     foreach ((array) $config->get('log.handlers') as $options) {
         $level = isset($options['level']) ? $options['level'] : $config->get('log.level', Monologger::INFO);
         $type = isset($options['type']) ? $options['type'] : '';
         $handler = null;
         // skip disabled handlers
         if (isset($options['enabled']) && !$options['enabled']) {
             continue;
         }
         // skip writer if channel doesn't match
         if (isset($options['channel']) && !self::channelMatch($name, (array) $options['channel'])) {
             continue;
         }
         // convert log level to a numeric value
         if (!is_numeric($level) && isset(self::$levels[strtolower($level)])) {
             $level = self::$levels[strtolower($level)];
         }
         switch ($type) {
             case 'file':
                 $logdir = Utils::abspath(dirname($options['path']), '/');
                 $options['path'] = $logdir . basename($options['path']);
             case 'stream':
                 $handler = new StreamHandler($options['path'], $level);
                 break;
             case 'cli':
                 if (php_sapi_name() === 'cli-server') {
                     $handler = new StreamHandler('php://stdout', $level);
                 }
                 break;
             case 'syslog':
                 $identity = isset($options['identity']) ? $options['identity'] : $config->get('log.name', 'roundcube');
                 $facility = isset($options['facility']) ? $options['facility'] : $config->get('log.facility', 'user');
                 $handler = new SyslogHandler($identity, $facility, $level);
                 break;
             default:
                 // TODO: allow full class names and check if implements Monolog\Handler\HandlerInterface
         }
         if ($handler) {
             self::addFormatter($handler, $options);
             $logger->pushHandler($handler);
             $handlers++;
         }
     }
     // add null handler if no handlers have been added
     if ($handlers === 0) {
         $logger->pushHandler(new NullHandler());
     }
 }
コード例 #2
0
 /**
  *
  */
 public function url($route, $full = false)
 {
     $url = $this->httpRequest->getBaseUrl() . $route;
     return $full ? Utils::fullyQualifiedUrl($url) : $url;
 }