[ Index ]
 

Code source de Symfony 1.0.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/config/ -> sfLoggingConfigHandler.class.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of the symfony package.
   5   * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
   6   *
   7   * For the full copyright and license information, please view the LICENSE
   8   * file that was distributed with this source code.
   9   */
  10  
  11  /**
  12   * sfLoggingConfigHandler allows you to configure logging and register loggers with the system.
  13   *
  14   * @package    symfony
  15   * @subpackage config
  16   * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
  17   * @version    SVN: $Id: sfLoggingConfigHandler.class.php 3258 2007-01-13 12:12:22Z fabien $
  18   */
  19  class sfLoggingConfigHandler extends sfDefineEnvironmentConfigHandler
  20  {
  21    protected
  22      $enabled = true,
  23      $loggers = array();
  24  
  25    /**
  26     * Executes this configuration handler.
  27     *
  28     * @param array An array of absolute filesystem path to a configuration file
  29     *
  30     * @return string Data to be written to a cache file
  31     */
  32    public function execute($configFiles)
  33    {
  34      $data = parent::execute($configFiles);
  35  
  36      if ($this->enabled)
  37      {
  38        $data .= "\n\$logger = sfLogger::getInstance();\n";
  39  
  40        // log level
  41        $data .= "\$logger->setLogLevel(constant('SF_LOG_'.strtoupper(sfConfig::get('sf_logging_level'))));\n";
  42  
  43        // register loggers defined in the logging.yml configuration file
  44        foreach ($this->loggers as $name => $keys)
  45        {
  46          if (isset($keys['enabled']) && !$keys['enabled'])
  47          {
  48            continue;
  49          }
  50  
  51          if (!isset($keys['class']))
  52          {
  53            // missing class key
  54            throw new sfParseException(sprintf('Configuration file "%s" specifies filter "%s" with missing class key', $configFiles[0], $name));
  55          }
  56  
  57          $condition = true;
  58          if (isset($keys['param']['condition']))
  59          {
  60            $condition = $this->replaceConstants($keys['param']['condition']);
  61            unset($keys['param']['condition']);
  62          }
  63  
  64          if ($condition)
  65          {
  66            // parse parameters
  67            $parameters = isset($keys['param']) ? var_export($keys['param'], true) : '';
  68  
  69            // create logger instance
  70            $data .= sprintf("\n\$log = new %s();\n\$log->initialize(%s);\n\$logger->registerLogger(\$log);\n", $keys['class'], $parameters);
  71          }
  72        }
  73      }
  74  
  75      return $data;
  76    }
  77  
  78    protected function getValues($prefix, $category, $keys)
  79    {
  80      if ('enabled' == $category)
  81      {
  82        $this->enabled = $this->replaceConstants($keys);
  83      }
  84      else if ('loggers' == $category)
  85      {
  86        $this->loggers = $this->replaceConstants($keys);
  87  
  88        return array();
  89      }
  90  
  91      return parent::getValues($prefix, $category, $keys);
  92    }
  93  }


Généré le : Fri Mar 16 22:42:14 2007 par Balluche grâce à PHPXref 0.7