Commit 689e5d16 by Qiang Xue

renamed "logging" to "log".

parent 6033e200
......@@ -10,7 +10,7 @@ use yii\base\Exception;
use yii\base\InvalidConfigException;
use yii\base\InvalidParamException;
use yii\base\UnknownClassException;
use yii\logging\Logger;
use yii\log\Logger;
/**
* Gets the application start timestamp.
......@@ -478,7 +478,7 @@ class YiiBase
public static function trace($message, $category = 'application')
{
if (YII_DEBUG) {
self::getLogger()->log($message, Logger::LEVEL_TRACE, $category);
self::$app->getLog()->log($message, Logger::LEVEL_TRACE, $category);
}
}
......@@ -491,7 +491,7 @@ class YiiBase
*/
public static function error($message, $category = 'application')
{
self::getLogger()->log($message, Logger::LEVEL_ERROR, $category);
self::$app->getLog()->log($message, Logger::LEVEL_ERROR, $category);
}
/**
......@@ -503,7 +503,7 @@ class YiiBase
*/
public static function warning($message, $category = 'application')
{
self::getLogger()->log($message, Logger::LEVEL_WARNING, $category);
self::$app->getLog()->log($message, Logger::LEVEL_WARNING, $category);
}
/**
......@@ -515,7 +515,7 @@ class YiiBase
*/
public static function info($message, $category = 'application')
{
self::getLogger()->log($message, Logger::LEVEL_INFO, $category);
self::$app->getLog()->log($message, Logger::LEVEL_INFO, $category);
}
/**
......@@ -537,7 +537,7 @@ class YiiBase
*/
public static function beginProfile($token, $category = 'application')
{
self::getLogger()->log($token, Logger::LEVEL_PROFILE_BEGIN, $category);
self::$app->getLog()->log($token, Logger::LEVEL_PROFILE_BEGIN, $category);
}
/**
......@@ -549,29 +549,7 @@ class YiiBase
*/
public static function endProfile($token, $category = 'application')
{
self::getLogger()->log($token, Logger::LEVEL_PROFILE_END, $category);
}
/**
* Returns the message logger object.
* @return \yii\logging\Logger message logger
*/
public static function getLogger()
{
if (self::$_logger !== null) {
return self::$_logger;
} else {
return self::$_logger = new Logger;
}
}
/**
* Sets the logger object.
* @param Logger $logger the logger object.
*/
public static function setLogger($logger)
{
self::$_logger = $logger;
self::$app->getLog()->log($token, Logger::LEVEL_PROFILE_END, $category);
}
/**
......
......@@ -266,6 +266,15 @@ abstract class Application extends Module
}
/**
* Returns the log component.
* @return \yii\log\Logger the log component
*/
public function getLog()
{
return $this->getComponent('log');
}
/**
* Returns the error handler component.
* @return ErrorHandler the error handler application component.
*/
......@@ -344,6 +353,9 @@ abstract class Application extends Module
public function registerCoreComponents()
{
$this->setComponents(array(
'log' => array(
'class' => 'yii\log\Logger',
),
'errorHandler' => array(
'class' => 'yii\base\ErrorHandler',
),
......
......@@ -41,13 +41,12 @@ return array(
'yii\web\AssetBundle' => YII_PATH . '/web/AssetBundle.php',
'yii\web\AssetConverter' => YII_PATH . '/web/AssetConverter.php',
'yii\web\HeaderCollection' => YII_PATH . '/web/HeaderCollection.php',
'yii\logging\Target' => YII_PATH . '/logging/Target.php',
'yii\logging\DebugTarget' => YII_PATH . '/logging/DebugTarget.php',
'yii\logging\Router' => YII_PATH . '/logging/Router.php',
'yii\logging\Logger' => YII_PATH . '/logging/Logger.php',
'yii\logging\EmailTarget' => YII_PATH . '/logging/EmailTarget.php',
'yii\logging\DbTarget' => YII_PATH . '/logging/DbTarget.php',
'yii\logging\FileTarget' => YII_PATH . '/logging/FileTarget.php',
'yii\log\Target' => YII_PATH . '/logging/Target.php',
'yii\log\DebugTarget' => YII_PATH . '/logging/DebugTarget.php',
'yii\log\Logger' => YII_PATH . '/logging/Logger.php',
'yii\log\EmailTarget' => YII_PATH . '/logging/EmailTarget.php',
'yii\log\DbTarget' => YII_PATH . '/logging/DbTarget.php',
'yii\log\FileTarget' => YII_PATH . '/logging/FileTarget.php',
'yii\widgets\ActiveField' => YII_PATH . '/widgets/ActiveField.php',
'yii\widgets\Captcha' => YII_PATH . '/widgets/Captcha.php',
'yii\widgets\ListPager' => YII_PATH . '/widgets/ListPager.php',
......
......@@ -8,7 +8,7 @@
namespace yii\debug;
use Yii;
use yii\logging\Target;
use yii\log\Target;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
......
......@@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/
*/
namespace yii\logging;
namespace yii\log;
use Yii;
use yii\db\Connection;
......
......@@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/
*/
namespace yii\logging;
namespace yii\log;
/**
* EmailTarget sends selected log messages to the specified email addresses.
......
......@@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/
*/
namespace yii\logging;
namespace yii\log;
use Yii;
use yii\base\InvalidConfigException;
......
......@@ -5,13 +5,57 @@
* @license http://www.yiiframework.com/license/
*/
namespace yii\logging;
namespace yii\log;
use \yii\base\Component;
use \yii\base\InvalidConfigException;
/**
* Logger records logged messages in memory.
* Logger records logged messages in memory and sends them to different targets as needed.
*
* Logger is registered as a core application component and can be accessed using `Yii::$app->log`.
* You can call the method [[log()]] to record a single log message. For convenience, a set of shortcut
* methods are provided for logging messages of various severity levels via the [[Yii]] class:
*
* - [[Yii::trace()]]
* - [[Yii::error()]]
* - [[Yii::warning()]]
* - [[Yii::info()]]
* - [[Yii::beginProfile()]]
* - [[Yii::endProfile()]]
*
* When enough messages are accumulated in the logger, or when the current request finishes,
* the logged messages will be sent to different [[targets]], such as log files, emails.
*
* You may configure the targets in application configuration, like the following:
*
* ~~~
* array(
* 'components' => array(
* 'log' => array(
* 'targets' => array(
* 'file' => array(
* 'class' => 'yii\log\FileTarget',
* 'levels' => array('trace', 'info'),
* 'categories' => array('yii\*'),
* ),
* 'email' => array(
* 'class' => 'yii\log\EmailTarget',
* 'levels' => array('error', 'warning'),
* 'emails' => array('admin@example.com'),
* ),
* ),
* ),
* ),
* )
* ~~~
*
* Each log target can have a name and can be referenced via the [[targets]] property
* as follows:
*
* ~~~
* Yii::$app->log->targets['file']->enabled = false;
* ~~~
*
* When the application ends or [[flushInterval]] is reached, Logger will call [[flush()]]
* to send logged messages to different log targets, such as file, email, Web.
......@@ -65,7 +109,7 @@ class Logger extends Component
*/
public $flushInterval = 1000;
/**
* @var array logged messages. This property is mainly managed by [[log()]] and [[flush()]].
* @var array logged messages. This property is managed by [[log()]] and [[flush()]].
* Each log message is of the following structure:
*
* ~~~
......@@ -79,9 +123,10 @@ class Logger extends Component
*/
public $messages = array();
/**
* @var Router the log target router registered with this logger.
* @var array the log targets. Each array element represents a single [[Target|log target]] instance
* or the configuration for creating the log target instance.
*/
public $router;
public $targets = array();
/**
......
......@@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/
*/
namespace yii\logging;
namespace yii\log;
use Yii;
use yii\base\Component;
......@@ -27,15 +27,15 @@ use yii\base\Component;
* 'preload' => array('log'),
* 'components' => array(
* 'log' => array(
* 'class' => 'yii\logging\Router',
* 'class' => 'yii\log\Router',
* 'targets' => array(
* 'file' => array(
* 'class' => 'yii\logging\FileTarget',
* 'class' => 'yii\log\FileTarget',
* 'levels' => array('trace', 'info'),
* 'categories' => array('yii\*'),
* ),
* 'email' => array(
* 'class' => 'yii\logging\EmailTarget',
* 'class' => 'yii\log\EmailTarget',
* 'levels' => array('error', 'warning'),
* 'emails' => array('admin@example.com'),
* ),
......
......@@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/
*/
namespace yii\logging;
namespace yii\log;
use Yii;
use yii\base\Component;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment