Changeset 4710
- Timestamp:
- 07/25/07 07:43:14 (1 year ago)
- Files:
-
- trunk/lib/action/sfComponent.class.php (modified) (1 diff)
- trunk/lib/config/sfLoggingConfigHandler.class.php (modified) (1 diff)
- trunk/lib/helper/DebugHelper.php (modified) (1 diff)
- trunk/lib/log/sfLogger.class.php (modified) (15 diffs)
- trunk/lib/log/sfLogger/sfFileLogger.class.php (modified) (4 diffs)
- trunk/lib/log/sfLogger/sfWebDebugLogger.class.php (modified) (2 diffs)
- trunk/test/unit/log/sfLoggerTest.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/action/sfComponent.class.php
r4597 r4710 112 112 if (sfConfig::get('sf_logging_enabled')) 113 113 { 114 $this->context->getLogger()->log($message, constant(' SF_LOG_'.strtoupper($priority)));114 $this->context->getLogger()->log($message, constant('sfLogger::'.strtoupper($priority))); 115 115 } 116 116 } trunk/lib/config/sfLoggingConfigHandler.class.php
r4597 r4710 39 39 40 40 // 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"; 42 42 43 43 // register loggers defined in the logging.yml configuration file trunk/lib/helper/DebugHelper.php
r2808 r4710 13 13 if (sfConfig::get('sf_logging_enabled')) 14 14 { 15 sfContext::getInstance()->getLogger()->log($message, constant(' SF_LOG_'.strtoupper($priority)));15 sfContext::getInstance()->getLogger()->log($message, constant('sfLogger::'.strtoupper($priority))); 16 16 } 17 17 } trunk/lib/log/sfLogger.class.php
r4597 r4710 9 9 */ 10 10 11 define('SF_LOG_EMERG', 0); // System is unusable12 define('SF_LOG_ALERT', 1); // Immediate action required13 define('SF_LOG_CRIT', 2); // Critical conditions14 define('SF_LOG_ERR', 3); // Error conditions15 define('SF_LOG_WARNING', 4); // Warning conditions16 define('SF_LOG_NOTICE', 5); // Normal but significant17 define('SF_LOG_INFO', 6); // Informational18 define('SF_LOG_DEBUG', 7); // Debug-level messages19 20 11 /** 21 12 * sfLogger manages all logging in symfony projects. … … 24 15 * Loggers can also be registered directly in the logging.yml configuration file. 25 16 * 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): 27 18 * - EMERG: System is unusable 28 19 * - ALERT: Immediate action required … … 41 32 class sfLogger 42 33 { 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 43 43 protected 44 44 $loggers = array(), 45 $level = SF_LOG_EMERG;45 $level = self::INFO; 46 46 47 47 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; 59 49 60 50 /** … … 65 55 public static function getInstance() 66 56 { 67 if (!s fLogger::$logger)57 if (!self::$logger) 68 58 { 69 59 // the class exists 70 60 $class = __CLASS__; 71 s fLogger::$logger = new $class();72 s fLogger::$logger->initialize();73 } 74 75 return s fLogger::$logger;61 self::$logger = new $class(); 62 self::$logger->initialize(); 63 } 64 65 return self::$logger; 76 66 } 77 67 … … 130 120 * @param string Message priority 131 121 */ 132 public function log($message, $priority = SF_LOG_INFO)122 public function log($message, $priority = self::INFO) 133 123 { 134 124 if ($this->level < $priority) … … 144 134 145 135 /** 146 * Sets an emerg message.136 * Logs an emerg message. 147 137 * 148 138 * @param string Message … … 150 140 public function emerg($message) 151 141 { 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. 157 147 * 158 148 * @param string Message … … 160 150 public function alert($message) 161 151 { 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. 167 157 * 168 158 * @param string Message … … 170 160 public function crit($message) 171 161 { 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. 177 167 * 178 168 * @param string Message … … 180 170 public function err($message) 181 171 { 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. 187 177 * 188 178 * @param string Message … … 190 180 public function warning($message) 191 181 { 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. 197 187 * 198 188 * @param string Message … … 200 190 public function notice($message) 201 191 { 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. 207 197 * 208 198 * @param string Message … … 210 200 public function info($message) 211 201 { 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. 217 207 * 218 208 * @param string Message … … 220 210 public function debug($message) 221 211 { 222 $this->log($message, SF_LOG_DEBUG);212 $this->log($message, self::DEBUG); 223 213 } 224 214 … … 243 233 public static function getPriorityName($priority) 244 234 { 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])) 246 247 { 247 248 throw new sfException(sprintf('The priority level "%s" does not exist.', $priority)); 248 249 } 249 250 250 return self::$levels[$priority];251 return $levels[$priority]; 251 252 } 252 253 } trunk/lib/log/sfLogger/sfFileLogger.class.php
r4597 r4710 10 10 11 11 /** 12 * sfFileLogger logs messages in a file. 12 13 * 13 14 * @package symfony … … 22 23 23 24 /** 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 25 31 * 26 32 * @param array Options for the logger … … 34 40 35 41 $dir = dirname($options['file']); 36 37 42 if (!is_dir($dir)) 38 43 { 39 mkdir($dir, 0777, 1);44 mkdir($dir, 0777, true); 40 45 } 41 46 … … 56 61 public function log($message, $priority = null) 57 62 { 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 60 63 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")); 62 65 flock($this->fp, LOCK_UN); 63 66 } trunk/lib/log/sfLogger/sfWebDebugLogger.class.php
r4193 r4710 10 10 11 11 /** 12 * sfWebDebugLogger logs messages into the web debug toolbar. 12 13 * 13 14 * @package symfony … … 22 23 23 24 /** 24 * Initializes th e web debuglogger.25 * Initializes this logger. 25 26 * 26 27 * @param array Logger options trunk/test/unit/log/sfLoggerTest.php
r4193 r4710 52 52 // ->setLogLevel() ->getLogLevel() 53 53 $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'); 57 57 58 58 // ->log() 59 59 $t->diag('->log()'); 60 60 $logger->initialize(); 61 $logger->setLogLevel( SF_LOG_DEBUG);61 $logger->setLogLevel(sfLogger::DEBUG); 62 62 $logger->registerLogger($myRealLogger); 63 63 $logger->registerLogger($myRealLogger); … … 69 69 foreach (array('emerg', 'alert', 'crit', 'err', 'warning', 'notice', 'info', 'debug') as $level) 70 70 { 71 $levelConstant = ' SF_LOG_'.strtoupper($level);71 $levelConstant = 'sfLogger::'.strtoupper($level); 72 72 73 73 foreach (array('emerg', 'alert', 'crit', 'err', 'warning', 'notice', 'info', 'debug') as $logLevel) 74 74 { 75 $logLevelConstant = ' SF_LOG_'.strtoupper($logLevel);75 $logLevelConstant = 'sfLogger::'.strtoupper($logLevel); 76 76 $logger->setLogLevel(constant($logLevelConstant)); 77 77 … … 87 87 foreach (array('emerg', 'alert', 'crit', 'err', 'warning', 'notice', 'info', 'debug') as $level) 88 88 { 89 $levelConstant = ' SF_LOG_'.strtoupper($level);89 $levelConstant = 'sfLogger::'.strtoupper($level); 90 90 91 91 foreach (array('emerg', 'alert', 'crit', 'err', 'warning', 'notice', 'info', 'debug') as $logLevel) 92 92 { 93 $logger->setLogLevel(constant(' SF_LOG_'.strtoupper($logLevel)));93 $logger->setLogLevel(constant('sfLogger::'.strtoupper($logLevel))); 94 94 95 95 $myRealLogger->log = '';