[ Index ]
 

Code source de Symfony 1.0.0

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

title

Body

[fermer]

/lib/log/ -> sfLogger.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  define('SF_LOG_EMERG',   0); // System is unusable
  12  define('SF_LOG_ALERT',   1); // Immediate action required
  13  define('SF_LOG_CRIT',    2); // Critical conditions
  14  define('SF_LOG_ERR',     3); // Error conditions
  15  define('SF_LOG_WARNING', 4); // Warning conditions
  16  define('SF_LOG_NOTICE',  5); // Normal but significant
  17  define('SF_LOG_INFO',    6); // Informational
  18  define('SF_LOG_DEBUG',   7); // Debug-level messages
  19  
  20  /**
  21   * sfLogger manages all logging in symfony projects.
  22   *
  23   * sfLogger can be configuration via the logging.yml configuration file.
  24   * Loggers can also be registered directly in the logging.yml configuration file.
  25   *
  26   * This level list is ordered by highest priority (SF_LOG_EMERG) to lowest priority (SF_LOG_DEBUG):
  27   * - EMERG:   System is unusable
  28   * - ALERT:   Immediate action required
  29   * - CRIT:    Critical conditions
  30   * - ERR:     Error conditions
  31   * - WARNING: Warning conditions
  32   * - NOTICE:  Normal but significant
  33   * - INFO:    Informational
  34   * - DEBUG:   Debug-level messages
  35   *
  36   * @package    symfony
  37   * @subpackage log
  38   * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
  39   * @version    SVN: $Id: sfLogger.class.php 3329 2007-01-23 08:29:34Z fabien $
  40   */
  41  class sfLogger
  42  {
  43    protected
  44      $loggers = array(),
  45      $level   = SF_LOG_EMERG,
  46      $levels  = array(
  47        SF_LOG_EMERG   => 'emerg',
  48        SF_LOG_ALERT   => 'alert',
  49        SF_LOG_CRIT    => 'crit',
  50        SF_LOG_ERR     => 'err',
  51        SF_LOG_WARNING => 'warning',
  52        SF_LOG_NOTICE  => 'notice',
  53        SF_LOG_INFO    => 'info',
  54        SF_LOG_DEBUG   => 'debug',
  55      );
  56  
  57    protected static
  58      $logger = null;
  59  
  60    /**
  61     * Returns the sfLogger instance.
  62     *
  63     * @return  object the sfLogger instance
  64     */
  65    public static function getInstance()
  66    {
  67      if (!sfLogger::$logger)
  68      {
  69        // the class exists
  70        $class = __CLASS__;
  71        sfLogger::$logger = new $class();
  72        sfLogger::$logger->initialize();
  73      }
  74  
  75      return sfLogger::$logger;
  76    }
  77  
  78    /**
  79     * Initializes the logger.
  80     */
  81    public function initialize()
  82    {
  83      $this->loggers = array();
  84    }
  85  
  86    /**
  87     * Retrieves the log level for the current logger instance.
  88     *
  89     * @return string Log level
  90     */
  91    public function getLogLevel()
  92    {
  93      return $this->level;
  94    }
  95  
  96    /**
  97     * Sets a log level for the current logger instance.
  98     *
  99     * @param string Log level
 100     */
 101    public function setLogLevel($level)
 102    {
 103      $this->level = $level;
 104    }
 105    
 106    /**
 107     * Retrieves current loggers.
 108     *
 109     * @return array List of loggers
 110     */
 111    public function getLoggers()
 112    {
 113      return $this->loggers;
 114    }
 115    
 116    /**
 117     * Registers a logger.
 118     *
 119     * @param string Logger name
 120     */
 121    public function registerLogger($logger)
 122    {
 123      $this->loggers[] = $logger;
 124    }
 125  
 126    /**
 127     * Logs a message.
 128     *
 129     * @param string Message
 130     * @param string Message priority
 131     */
 132    public function log($message, $priority = SF_LOG_INFO)
 133    {
 134      if ($this->level < $priority)
 135      {
 136        return;
 137      }
 138  
 139      foreach ($this->loggers as $logger)
 140      {
 141        $logger->log((string) $message, $priority, $this->levels[$priority]);
 142      }
 143    }
 144  
 145    /**
 146     * Sets an emerg message.
 147     *
 148     * @param string Message
 149     */
 150    public function emerg($message)
 151    {
 152      $this->log($message, SF_LOG_EMERG);
 153    }
 154  
 155    /**
 156     * Sets an alert message.
 157     *
 158     * @param string Message
 159     */
 160    public function alert($message)
 161    {
 162      $this->log($message, SF_LOG_ALERT);
 163    }
 164  
 165    /**
 166     * Sets a critical message.
 167     *
 168     * @param string Message
 169     */
 170    public function crit($message)
 171    {
 172      $this->log($message, SF_LOG_CRIT);
 173    }
 174  
 175    /**
 176     * Sets an error message.
 177     *
 178     * @param string Message
 179     */
 180    public function err($message)
 181    {
 182      $this->log($message, SF_LOG_ERR);
 183    }
 184  
 185    /**
 186     * Sets a warning message.
 187     *
 188     * @param string Message
 189     */
 190    public function warning($message)
 191    {
 192      $this->log($message, SF_LOG_WARNING);
 193    }
 194  
 195    /**
 196     * Sets a notice message.
 197     *
 198     * @param string Message
 199     */
 200    public function notice($message)
 201    {
 202      $this->log($message, SF_LOG_NOTICE);
 203    }
 204  
 205    /**
 206     * Sets an info message.
 207     *
 208     * @param string Message
 209     */
 210    public function info($message)
 211    {
 212      $this->log($message, SF_LOG_INFO);
 213    }
 214  
 215    /**
 216     * Sets a debug message.
 217     *
 218     * @param string Message
 219     */
 220    public function debug($message)
 221    {
 222      $this->log($message, SF_LOG_DEBUG);
 223    }
 224  
 225    /**
 226     * Executes the shutdown procedure.
 227     *
 228     * Cleans up the current logger instance.
 229     */
 230    public function shutdown()
 231    {
 232      foreach ($this->loggers as $logger)
 233      {
 234        if (method_exists($logger, 'shutdown'))
 235        {
 236          $logger->shutdown();
 237        }
 238      }
 239  
 240      $this->loggers = array();
 241    }
 242  }


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