Skip to content

Commit

Permalink
Making CakeLog a static class, removing PHP4 workarounds and no longe…
Browse files Browse the repository at this point in the history
…r needed singleton. Removes CakeLog::getInstance()
  • Loading branch information
markstory committed Apr 14, 2010
1 parent c4d57bd commit cd42047
Showing 1 changed file with 15 additions and 35 deletions.
50 changes: 15 additions & 35 deletions cake/libs/cake_log.php
Expand Up @@ -54,21 +54,7 @@ class CakeLog {
* @var array
* @access protected
*/
protected $_streams = array();

/**
* Get an instance
*
* @return void
* @static
*/
function &getInstance() {
static $instance = array();
if (!isset($instance[0])) {
$instance[0] =& new CakeLog();
}
return $instance[0];
}
protected static $_streams = array();

/**
* Configure and add a new logging stream to CakeLog
Expand Down Expand Up @@ -101,13 +87,12 @@ function config($key, $config) {
trigger_error(__('Missing logger classname', true), E_USER_WARNING);
return false;
}
$self =& CakeLog::getInstance();
$className = $self->_getLogger($config['engine']);
$className = self::_getLogger($config['engine']);
if (!$className) {
return false;
}
unset($config['engine']);
$self->_streams[$key] = new $className($config);
self::$_streams[$key] = new $className($config);
return true;
}

Expand All @@ -118,7 +103,7 @@ function config($key, $config) {
* @param string $loggerName the plugin.className of the logger class you want to build.
* @return mixed boolean false on any failures, string of classname to use if search was successful.
*/
protected function _getLogger($loggerName) {
protected static function _getLogger($loggerName) {
list($plugin, $loggerName) = pluginSplit($loggerName);

if ($plugin) {
Expand Down Expand Up @@ -149,9 +134,8 @@ protected function _getLogger($loggerName) {
* @access public
* @static
*/
function configured() {
$self =& CakeLog::getInstance();
return array_keys($self->_streams);
public static function configured() {
return array_keys(self::$_streams);
}

/**
Expand All @@ -163,21 +147,20 @@ function configured() {
* @access public
* @static
*/
function drop($streamName) {
$self =& CakeLog::getInstance();
unset($self->_streams[$streamName]);
public static function drop($streamName) {
unset(self::$_streams[$streamName]);
}

/**
* Configures the automatic/default stream a FileLog.
*
* @return void
*/
protected function _autoConfig() {
protected static function _autoConfig() {
if (!class_exists('FileLog')) {
App::import('Core', 'log/FileLog');
}
$this->_streams['default'] =& new FileLog(array('path' => LOGS));
self::$_streams['default'] = new FileLog(array('path' => LOGS));
}

/**
Expand Down Expand Up @@ -206,7 +189,7 @@ protected function _autoConfig() {
* @access public
* @static
*/
function write($type, $message) {
public static function write($type, $message) {
if (!defined('LOG_ERROR')) {
define('LOG_ERROR', 2);
}
Expand All @@ -225,13 +208,10 @@ function write($type, $message) {
if (is_int($type) && isset($levels[$type])) {
$type = $levels[$type];
}
$self =& CakeLog::getInstance();
if (empty($self->_streams)) {
$self->_autoConfig();
if (empty(self::$_streams)) {
self::_autoConfig();
}
$keys = array_keys($self->_streams);
foreach ($keys as $key) {
$logger =& $self->_streams[$key];
foreach (self::$_streams as $key => $logger) {
$logger->write($type, $message);
}
return true;
Expand All @@ -250,7 +230,7 @@ function write($type, $message) {
* @param array $context Context
* @return void
*/
function handleError($code, $description, $file = null, $line = null, $context = null) {
public static function handleError($code, $description, $file = null, $line = null, $context = null) {
if ($code === 2048 || $code === 8192) {
return;
}
Expand Down

0 comments on commit cd42047

Please sign in to comment.