/** * Writes the given message and type to all of the configured log adapters. * Configured adapters are passed both the $type and $message variables. $type * is one of the following strings/values. * * ### Types: * * - LOG_EMERG => 'emergency', * - LOG_ALERT => 'alert', * - LOG_CRIT => 'critical', * - `LOG_ERR` => 'error', * - `LOG_WARNING` => 'warning', * - `LOG_NOTICE` => 'notice', * - `LOG_INFO` => 'info', * - `LOG_DEBUG` => 'debug', * * ### Usage: * * Write a message to the 'warning' log: * * `CakeLog::write('warning', 'Stuff is broken here');` * * @param int|string $type Type of message being written. When value is an integer * or a string matching the recognized levels, then it will * be treated log levels. Otherwise it's treated as scope. * @param string $message Message content to log * @param string|array $scope The scope(s) a log message is being created in. * See CakeLog::config() for more information on logging scopes. * @return bool Success * @link http://book.cakephp.org/2.0/en/core-libraries/logging.html#writing-to-logs */ public static function write($type, $message, $scope = array()) { if (empty(static::$_Collection)) { static::_init(); } if (is_int($type) && isset(static::$_levels[$type])) { $type = static::$_levels[$type]; } if (is_string($type) && empty($scope) && !in_array($type, static::$_levels)) { $scope = $type; } $logged = false; foreach (static::$_Collection->enabled() as $streamName) { $logger = static::$_Collection->{$streamName}; $types = $scopes = $config = array(); if (method_exists($logger, 'config')) { $config = $logger->config(); } if (isset($config['types'])) { $types = $config['types']; } if (isset($config['scopes'])) { $scopes = $config['scopes']; } $inScope = count(array_intersect((array) $scope, $scopes)) > 0; $correctLevel = in_array($type, $types); if (empty($types) && empty($scopes) || in_array($type, $scopes) || empty($scopes) && $correctLevel || $correctLevel && $inScope) { $logger->write($type, $message); $logged = true; } } return $logged; }
/** * Writes the given message and type to all of the configured log adapters. * Configured adapters are passed both the $type and $message variables. $type * is one of the following strings/values. * * ### Types: * * - LOG_EMERG => 'emergency', * - LOG_ALERT => 'alert', * - LOG_CRIT => 'critical', * - `LOG_ERR` => 'error', * - `LOG_WARNING` => 'warning', * - `LOG_NOTICE` => 'notice', * - `LOG_INFO` => 'info', * - `LOG_DEBUG` => 'debug', * * ### Usage: * * Write a message to the 'warning' log: * * `CakeLog::write('warning', 'Stuff is broken here');` * * @param integer|string $type Type of message being written. When value is an integer * or a string matching the recognized levels, then it will * be treated log levels. Otherwise it's treated as scope. * @param string $message Message content to log * @param string|array $scope The scope(s) a log message is being created in. * See CakeLog::config() for more information on logging scopes. * @return boolean Success */ public static function write($type, $message, $scope = array()) { if (empty(self::$_Collection)) { self::_init(); } if (is_int($type) && isset(self::$_levels[$type])) { $type = self::$_levels[$type]; } if (is_string($type) && empty($scope) && !in_array($type, self::$_levels)) { $scope = $type; } $logged = false; foreach (self::$_Collection->enabled() as $streamName) { $logger = self::$_Collection->{$streamName}; $types = $scopes = $config = array(); if (method_exists($logger, 'config')) { $config = $logger->config(); } if (isset($config['types'])) { $types = $config['types']; } if (isset($config['scopes'])) { $scopes = $config['scopes']; } $inScope = (count(array_intersect((array)$scope, $scopes)) > 0); $correctLevel = in_array($type, $types); if ( // No config is a catch all (bc mode) (empty($types) && empty($scopes)) || // BC layer for mixing scope & level (in_array($type, $scopes)) || // no scopes, but has level (empty($scopes) && $correctLevel) || // exact scope + level ($correctLevel && $inScope) ) { $logger->write($type, $message); $logged = true; } } if (!$logged) { self::_autoConfig(); self::stream('default')->write($type, $message); } return true; }
/** * Writes the given message and type to all of the configured log adapters. * Configured adapters are passed both the $type and $message variables. $type * is one of the following strings/values. * * ### Types: * * - LOG_EMERG => 'emergency', * - LOG_ALERT => 'alert', * - LOG_CRIT => 'critical', * - `LOG_ERR` => 'error', * - `LOG_WARNING` => 'warning', * - `LOG_NOTICE` => 'notice', * - `LOG_INFO` => 'info', * - `LOG_DEBUG` => 'debug', * * ### Usage: * * Write a message to the 'warning' log: * * `CakeLog::write('warning', 'Stuff is broken here');` * * @param integer|string $type Type of message being written. When value is an integer * or a string matching the recognized levels, then it will * be treated log levels. Otherwise it's treated as scope. * @param string $message Message content to log * @param string|array $scope The scope(s) a log messge is being created in. * See CakeLog::config() for more information on logging scopes. * @return boolean Success */ public static function write($type, $message, $scope = array()) { if (empty(self::$_Collection)) { self::_init(); } if (is_int($type) && isset(self::$_levels[$type])) { $type = self::$_levels[$type]; } if (is_string($type) && empty($scope) && !in_array($type, self::$_levels)) { $scope = $type; } $logged = false; foreach (self::$_Collection->enabled() as $streamName) { $logger = self::$_Collection->{$streamName}; $types = null; $scopes = array(); if ($logger instanceof BaseLog) { $config = $logger->config(); if (isset($config['types'])) { $types = $config['types']; } if (isset($config['scopes'])) { $scopes = $config['scopes']; } } if (is_string($scope)) { $inScope = in_array($scope, $scopes); } else { $intersect = array_intersect($scope, $scopes); $inScope = !empty($intersect); } if (empty($types) || in_array($type, $types) || in_array($type, $scopes) && $inScope) { $logger->write($type, $message); $logged = true; } } if (!$logged) { self::_autoConfig(); self::stream('default')->write($type, $message); } return true; }
/** * Configures the automatic/default stream a FileLog. * * @return void */ protected static function _autoConfig() { self::$_Collection->load('default', array('engine' => 'File', 'path' => LOGS)); }