Development

Changeset 4710

You must first sign up to be able to contribute.

Changeset 4710

Show
Ignore:
Timestamp:
07/25/07 07:43:14 (1 year ago)
Author:
fabien
Message:

changed logger constants to class constants (for example SF_LOG_DEBUG is now sfLogger::DEBUG)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/action/sfComponent.class.php

    r4597 r4710  
    112112    if (sfConfig::get('sf_logging_enabled')) 
    113113    { 
    114       $this->context->getLogger()->log($message, constant('SF_LOG_'.strtoupper($priority))); 
     114      $this->context->getLogger()->log($message, constant('sfLogger::'.strtoupper($priority))); 
    115115    } 
    116116  } 
  • trunk/lib/config/sfLoggingConfigHandler.class.php

    r4597 r4710  
    3939 
    4040      // log level 
    41       $data .= "\$logger->setLogLevel(constant('SF_LOG_'.strtoupper(sfConfig::get('sf_logging_level'))));\n"; 
     41      $data .= "\$logger->setLogLevel(constant('sfLogger::'.strtoupper(sfConfig::get('sf_logging_level'))));\n"; 
    4242 
    4343      // register loggers defined in the logging.yml configuration file 
  • trunk/lib/helper/DebugHelper.php

    r2808 r4710  
    1313  if (sfConfig::get('sf_logging_enabled')) 
    1414  { 
    15     sfContext::getInstance()->getLogger()->log($message, constant('SF_LOG_'.strtoupper($priority))); 
     15    sfContext::getInstance()->getLogger()->log($message, constant('sfLogger::'.strtoupper($priority))); 
    1616  } 
    1717} 
  • trunk/lib/log/sfLogger.class.php

    r4597 r4710  
    99 */ 
    1010 
    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  
    2011/** 
    2112 * sfLogger manages all logging in symfony projects. 
     
    2415 * Loggers can also be registered directly in the logging.yml configuration file. 
    2516 * 
    26  * This level list is ordered by highest priority (SF_LOG_EMERG) to lowest priority (SF_LOG_DEBUG): 
     17 * This level list is ordered by highest priority (self::EMERG) to lowest priority (self::DEBUG): 
    2718 * - EMERG:   System is unusable 
    2819 * - ALERT:   Immediate action required 
     
    4132class sfLogger 
    4233{ 
     34  const EMERG   = 0; // System is unusable 
     35  const ALERT   = 1; // Immediate action required 
     36  const CRIT    = 2; // Critical conditions 
     37  const ERR     = 3; // Error conditions 
     38  const WARNING = 4; // Warning conditions 
     39  const NOTICE  = 5; // Normal but significant 
     40  const INFO    = 6; // Informational 
     41  const DEBUG   = 7; // Debug-level messages 
     42 
    4343  protected 
    4444    $loggers = array(), 
    45     $level   = SF_LOG_EMERG
     45    $level   = self::INFO
    4646 
    4747  protected static 
    48     $logger = null, 
    49     $levels  = array( 
    50       SF_LOG_EMERG   => 'emerg', 
    51       SF_LOG_ALERT   => 'alert', 
    52       SF_LOG_CRIT    => 'crit', 
    53       SF_LOG_ERR     => 'err', 
    54       SF_LOG_WARNING => 'warning', 
    55       SF_LOG_NOTICE  => 'notice', 
    56       SF_LOG_INFO    => 'info', 
    57       SF_LOG_DEBUG   => 'debug', 
    58     ); 
     48    $logger = null; 
    5949 
    6050  /** 
     
    6555  public static function getInstance() 
    6656  { 
    67     if (!sfLogger::$logger) 
     57    if (!self::$logger) 
    6858    { 
    6959      // the class exists 
    7060      $class = __CLASS__; 
    71       sfLogger::$logger = new $class(); 
    72       sfLogger::$logger->initialize(); 
    73     } 
    74  
    75     return sfLogger::$logger; 
     61      self::$logger = new $class(); 
     62      self::$logger->initialize(); 
     63    } 
     64 
     65    return self::$logger; 
    7666  } 
    7767 
     
    130120   * @param string Message priority 
    131121   */ 
    132   public function log($message, $priority = SF_LOG_INFO) 
     122  public function log($message, $priority = self::INFO) 
    133123  { 
    134124    if ($this->level < $priority) 
     
    144134 
    145135  /** 
    146    * Sets an emerg message. 
     136   * Logs an emerg message. 
    147137   * 
    148138   * @param string Message 
     
    150140  public function emerg($message) 
    151141  { 
    152     $this->log($message, SF_LOG_EMERG); 
    153   } 
    154  
    155   /** 
    156    * Sets an alert message. 
     142    $this->log($message, self::EMERG); 
     143  } 
     144 
     145  /** 
     146   * Logs an alert message. 
    157147   * 
    158148   * @param string Message 
     
    160150  public function alert($message) 
    161151  { 
    162     $this->log($message, SF_LOG_ALERT); 
    163   } 
    164  
    165   /** 
    166    * Sets a critical message. 
     152    $this->log($message, self::ALERT); 
     153  } 
     154 
     155  /** 
     156   * Logs a critical message. 
    167157   * 
    168158   * @param string Message 
     
    170160  public function crit($message) 
    171161  { 
    172     $this->log($message, SF_LOG_CRIT); 
    173   } 
    174  
    175   /** 
    176    * Sets an error message. 
     162    $this->log($message, self::CRIT); 
     163  } 
     164 
     165  /** 
     166   * Logs an error message. 
    177167   * 
    178168   * @param string Message 
     
    180170  public function err($message) 
    181171  { 
    182     $this->log($message, SF_LOG_ERR); 
    183   } 
    184  
    185   /** 
    186    * Sets a warning message. 
     172    $this->log($message, self::ERR); 
     173  } 
     174 
     175  /** 
     176   * Logs a warning message. 
    187177   * 
    188178   * @param string Message 
     
    190180  public function warning($message) 
    191181  { 
    192     $this->log($message, SF_LOG_WARNING); 
    193   } 
    194  
    195   /** 
    196    * Sets a notice message. 
     182    $this->log($message, self::WARNING); 
     183  } 
     184 
     185  /** 
     186   * Logs a notice message. 
    197187   * 
    198188   * @param string Message 
     
    200190  public function notice($message) 
    201191  { 
    202     $this->log($message, SF_LOG_NOTICE); 
    203   } 
    204  
    205   /** 
    206    * Sets an info message. 
     192    $this->log($message, self::NOTICE); 
     193  } 
     194 
     195  /** 
     196   * Logs an info message. 
    207197   * 
    208198   * @param string Message 
     
    210200  public function info($message) 
    211201  { 
    212     $this->log($message, SF_LOG_INFO); 
    213   } 
    214  
    215   /** 
    216    * Sets a debug message. 
     202    $this->log($message, self::INFO); 
     203  } 
     204 
     205  /** 
     206   * Logs a debug message. 
    217207   * 
    218208   * @param string Message 
     
    220210  public function debug($message) 
    221211  { 
    222     $this->log($message, SF_LOG_DEBUG); 
     212    $this->log($message, self::DEBUG); 
    223213  } 
    224214 
     
    243233  public static function getPriorityName($priority) 
    244234  { 
    245     if (!isset(self::$levels[$priority])) 
     235    static $levels  = array( 
     236      self::EMERG   => 'emerg', 
     237      self::ALERT   => 'alert', 
     238      self::CRIT    => 'crit', 
     239      self::ERR     => 'err', 
     240      self::WARNING => 'warning', 
     241      self::NOTICE  => 'notice', 
     242      self::INFO    => 'info', 
     243      self::DEBUG   => 'debug', 
     244    ); 
     245 
     246    if (!isset($levels[$priority])) 
    246247    { 
    247248      throw new sfException(sprintf('The priority level "%s" does not exist.', $priority)); 
    248249    } 
    249250 
    250     return self::$levels[$priority]; 
     251    return $levels[$priority]; 
    251252  } 
    252253} 
  • trunk/lib/log/sfLogger/sfFileLogger.class.php

    r4597 r4710  
    1010 
    1111/** 
     12 * sfFileLogger logs messages in a file. 
    1213 * 
    1314 * @package    symfony 
     
    2223 
    2324  /** 
    24    * Initializes the file logger. 
     25   * Initializes this logger. 
     26   * 
     27   * Available options: 
     28   * 
     29   * - file: The file path or a php wrapper to log messages 
     30   *         You can use any support php wrapper. To write logs to the Apache error log, use php://stderr 
    2531   * 
    2632   * @param array Options for the logger 
     
    3440 
    3541    $dir = dirname($options['file']); 
    36  
    3742    if (!is_dir($dir)) 
    3843    { 
    39       mkdir($dir, 0777, 1); 
     44      mkdir($dir, 0777, true); 
    4045    } 
    4146 
     
    5661  public function log($message, $priority = null) 
    5762  { 
    58     $line = sprintf("%s %s [%s] %s%s", strftime('%b %d %H:%M:%S'), 'symfony', sfLogger::getPriorityName($priority), $message, DIRECTORY_SEPARATOR == '\\' ? "\r\n" : "\n"); 
    59  
    6063    flock($this->fp, LOCK_EX); 
    61     fwrite($this->fp, $line); 
     64    fwrite($this->fp, sprintf("%s %s [%s] %s%s", strftime('%b %d %H:%M:%S'), 'symfony', sfLogger::getPriorityName($priority), $message, DIRECTORY_SEPARATOR == '\\' ? "\r\n" : "\n")); 
    6265    flock($this->fp, LOCK_UN); 
    6366  } 
  • trunk/lib/log/sfLogger/sfWebDebugLogger.class.php

    r4193 r4710  
    1010 
    1111/** 
     12 * sfWebDebugLogger logs messages into the web debug toolbar. 
    1213 * 
    1314 * @package    symfony 
     
    2223 
    2324  /** 
    24    * Initializes the web debug logger. 
     25   * Initializes this logger. 
    2526   * 
    2627   * @param array Logger options 
  • trunk/test/unit/log/sfLoggerTest.php

    r4193 r4710  
    5252// ->setLogLevel() ->getLogLevel() 
    5353$t->diag('->setLogLevel() ->getLogLevel()'); 
    54 $t->is($logger->getLogLevel(), SF_LOG_EMERG, '->getLogLevel() gets the current log level'); 
    55 $logger->setLogLevel(SF_LOG_WARNING); 
    56 $t->is($logger->getLogLevel(), SF_LOG_WARNING, '->setLogLevel() sets the log level'); 
     54$t->is($logger->getLogLevel(), sfLogger::INFO, '->getLogLevel() gets the current log level'); 
     55$logger->setLogLevel(sfLogger::WARNING); 
     56$t->is($logger->getLogLevel(), sfLogger::WARNING, '->setLogLevel() sets the log level'); 
    5757 
    5858// ->log() 
    5959$t->diag('->log()'); 
    6060$logger->initialize(); 
    61 $logger->setLogLevel(SF_LOG_DEBUG); 
     61$logger->setLogLevel(sfLogger::DEBUG); 
    6262$logger->registerLogger($myRealLogger); 
    6363$logger->registerLogger($myRealLogger); 
     
    6969foreach (array('emerg', 'alert', 'crit', 'err', 'warning', 'notice', 'info', 'debug') as $level) 
    7070{ 
    71   $levelConstant = 'SF_LOG_'.strtoupper($level); 
     71  $levelConstant = 'sfLogger::'.strtoupper($level); 
    7272 
    7373  foreach (array('emerg', 'alert', 'crit', 'err', 'warning', 'notice', 'info', 'debug') as $logLevel) 
    7474  { 
    75     $logLevelConstant = 'SF_LOG_'.strtoupper($logLevel); 
     75    $logLevelConstant = 'sfLogger::'.strtoupper($logLevel); 
    7676    $logger->setLogLevel(constant($logLevelConstant)); 
    7777 
     
    8787foreach (array('emerg', 'alert', 'crit', 'err', 'warning', 'notice', 'info', 'debug') as $level) 
    8888{ 
    89   $levelConstant = 'SF_LOG_'.strtoupper($level); 
     89  $levelConstant = 'sfLogger::'.strtoupper($level); 
    9090 
    9191  foreach (array('emerg', 'alert', 'crit', 'err', 'warning', 'notice', 'info', 'debug') as $logLevel) 
    9292  { 
    93     $logger->setLogLevel(constant('SF_LOG_'.strtoupper($logLevel))); 
     93    $logger->setLogLevel(constant('sfLogger::'.strtoupper($logLevel))); 
    9494 
    9595    $myRealLogger->log = '';