本文整理汇总了PHP中Yii::getLogger方法的典型用法代码示例。如果您正苦于以下问题:PHP Yii::getLogger方法的具体用法?PHP Yii::getLogger怎么用?PHP Yii::getLogger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Yii
的用法示例。
在下文中一共展示了Yii::getLogger方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getLogger
/**
* @return Logger
*/
public function getLogger()
{
if (!isset($this->_logger)) {
$this->_logger = \Yii::getLogger();
}
return $this->_logger;
}
示例2: assignInternalStaffAuth
/**
* Adds the current LDAP-authenticated user to the 'internal_staff_auth' permissions group.
*/
public function assignInternalStaffAuth()
{
$logger = \Yii::getLogger();
$logger->init();
$logger->flushInterval = 1;
$logger->traceLevel = 0;
$this->setIsNewRecord(True);
$this->item_name = "internal_staff_auth";
$this->user_id = (string) strval($this->user_id);
if (intval($this->user_id) > 0) {
$this->created_at = time();
$this->created_by = "system";
$this->updated_by = "system";
$this->save();
}
$msg = "gms: assignInternalStaffAuth() for UserId: " . $this->user_id;
\Yii::trace($msg . " (YT)", __METHOD__);
//Use the convenience method 'TRACE'
$logger->log($msg . " (LG)", 4);
if (!empty($this->getErrors())) {
$errs = $this->getErrors();
foreach ($errs as $err) {
foreach ($err as $item) {
$msg = "gms: ERR in assignInternalStaffAuth() -- " . $item;
//\Yii::trace($msg . " (YT)", __METHOD__); //Use the convenience method 'TRACE'
//$logger->log($msg . " (LG)", 4);
}
}
}
$logger->flush();
return null;
}
示例3: afterAction
protected function afterAction($action)
{
$time = sprintf('%0.5f', Yii::getLogger()->getExecutionTime());
$memory = round(memory_get_peak_usage() / (1024 * 1024), 2) . "MB";
echo '<!-- Time: ' . $time . 'ms, memory: ' . $memory . '-->';
parent::afterAction($action);
}
示例4: getDBLogs
public static function getDBLogs()
{
$results = array();
$n = 0;
foreach (Yii::getLogger()->getLogs() as $row) {
if ($row[1] == CLogger::LEVEL_PROFILE && strpos($row[2], 'system.db.CDbCommand') === 0) {
// echo CVarDumper::dumpAsString($row, 10, true);
$message = $row[0];
if (strncasecmp($message, 'begin:', 6) === 0) {
$row[0] = substr($message, 6);
$row[4] = $n;
$stack[] = $row;
$n++;
} else {
if (strncasecmp($message, 'end:', 4) === 0) {
$token = substr($message, 4);
if (($last = array_pop($stack)) !== null && $last[0] === $token) {
$delta = $row[3] - $last[3];
$results[$last[4]] = array($token, $delta, count($stack));
} else {
throw new CException(Yii::t('app', 'Mismatching code block "{token}". Make sure the calls to Yii::beginProfile() and Yii::endProfile() be properly nested.', array('{token}' => $token)));
}
}
}
}
}
$now = microtime(true);
while (null !== ($last = array_pop($stack))) {
$results[$last[4]] = array($last[0], $now - $last[3], count($stack));
}
ksort($results);
return array_map(array(__CLASS__, 'formatLog'), $results);
}
示例5: run
public function run()
{
$dbStat = Yii::app()->db->getStats();
$memory = round(Yii::getLogger()->memoryUsage / 1024 / 1024, 3);
$time = round(Yii::getLogger()->executionTime, 3);
echo "<div class='stat' id='stat'>\n <div style='float:left;padding-right:5px'> запросов: {$dbStat[0]} </div>\n <div style='float:left;padding-right:5px'> время: {$dbStat[1]} </div>\n <div style='float:left;padding-right:5px'> память: {$memory} </div>\n <div style='float:left;padding-right:5px'> выполнение: {$time} </div>\n </div>";
}
示例6: afterAction
protected function afterAction($action)
{
$time = sprintf('%0.5f', Yii::getLogger()->getExecutionTime());
$memory = round(memory_get_peak_usage() / (1024 * 1024), 2) . "MB";
echo "Time: {$time}, memory: {$memory}";
parent::afterAction($action);
}
示例7: register
public function register()
{
if ($this->getIsNewRecord() == false) {
throw new \RuntimeException('Calling "' . __CLASS__ . '::' . __METHOD__ . '" on existing user');
}
if ($this->module->enableConfirmation == false) {
$this->confirmed_at = time();
}
if ($this->module->enableGeneratingPassword) {
$this->password = Password::generate(8);
}
$this->trigger(self::USER_REGISTER_INIT);
if ($this->save()) {
$this->trigger(self::USER_REGISTER_DONE);
if ($this->module->enableConfirmation) {
$token = \Yii::createObject(['class' => Token::className(), 'type' => Token::TYPE_CONFIRMATION]);
$token->link('user', $this);
$this->mailer->sendConfirmationMessage($this, $token);
} else {
\Yii::$app->user->login($this);
}
if ($this->module->enableGeneratingPassword) {
$this->mailer->sendWelcomeMessage($this);
}
\Yii::$app->session->setFlash('info', $this->getFlashMessage());
\Yii::getLogger()->log('User has been registered', Logger::LEVEL_INFO);
return true;
}
\Yii::getLogger()->log('An error occurred while registering user account', Logger::LEVEL_ERROR);
return false;
}
示例8: actionConfirm
/**
* Overrided Confirm action
*
* @param int $id
* @param string $code
* @return string
* @throws NotFoundHttpException
* @throws \Exception
*/
public function actionConfirm($id, $code)
{
$user = $this->finder->findUserById($id);
//$mailer = \Yii::$container->get(dektriumMailer::className());
$mailer = new \common\helpers\Mandrill($user->email, 'Welcome to Razzd!', 'welcome', $sender = null, ['user' => $user, 'mandrill_template_name' => 'welcome']);
if ($user === null || $this->module->enableConfirmation == false) {
throw new NotFoundHttpException();
}
/** @var Token $token */
$token = $this->findToken($id, $code, Token::TYPE_CONFIRMATION);
if ($token === null || $token->isExpired) {
\Yii::$app->session->setFlash('danger', \Yii::t('user', 'The confirmation link is invalid or expired. Please try requesting a new one.'));
} else {
$token->delete();
$user->confirmed_at = time();
\Yii::$app->user->login($user);
\Yii::getLogger()->log('User has been confirmed', Logger::LEVEL_INFO);
if ($user->save(false)) {
\Yii::$app->session->setFlash('success', \Yii::t('user', 'Thank you, registration is now complete.'));
$mailer->sendMessage();
} else {
\Yii::$app->session->setFlash('danger', \Yii::t('user', 'Something went wrong and your account has not been confirmed.'));
}
}
return $this->render('/message', ['title' => \Yii::t('user', 'Account confirmation'), 'module' => $this->module]);
}
示例9: run
/**
* {@inheritdoc}
*/
public function run()
{
$resources = array(YiiDebug::t('Page Load Time') => sprintf('%0.3F s.', $this->getLoadTime()), YiiDebug::t('Elapsed Time') => sprintf('%0.3F s.', $this->getRequestLoadTime()), YiiDebug::t('Memory Usage') => number_format(Yii::getLogger()->getMemoryUsage() / 1024) . ' KB', YiiDebug::t('Memory Peak Usage') => number_format(memory_get_peak_usage() / 1024) . ' KB');
if (function_exists('mb_strlen') && isset($_SESSION)) {
$resources[YiiDebug::t('Session Size')] = sprintf('%0.3F KB', mb_strlen(serialize($_SESSION)) / 1024);
}
$this->render('resource_usage', array('resources' => $resources));
}
示例10: log
/**
* Logs a message.
* @param int $level The logging level.
* @param string $message The message to be logged.
* @param array $context The log context.
* @throws InvalidParamException The specified logging level is unknown.
*/
public function log($level, $message, array $context = [])
{
if (!isset(static::$levels[$level])) {
$values = implode(', ', (new \ReflectionClass('\\Mustache_Logger'))->getConstants());
throw new InvalidParamException("Invalid enumerable value \"{$level}\". Please make sure it is among ({$values}).");
}
\Yii::getLogger()->log($message, static::$levels[$level], __METHOD__);
}
示例11: init
/**
* Initialize the command object.
*/
public function init()
{
// Tell yii to flush the logs every message (instead of buffering for the default 10,000)
// Without this, you cannot use the log to find out where the script has got to in it's current run.
Yii::getLogger()->autoFlush = 1;
Yii::getLogger()->autoDump = true;
parent::init();
}
示例12: init
public function init()
{
parent::init();
$logger = Yii::getLogger();
$logger->autoFlush = $this->autoFlush;
$logger->detachEventHandler('onFlush', array($this, 'collectLogs'));
$logger->attachEventHandler('onFlush', array($this, 'processLogs'));
}
示例13: getQueryCount
protected function getQueryCount()
{
$logger = Yii::getLogger();
if ($logger === null) {
$this->markTestSkipped('I have not a logger');
}
return $logger->getDbProfiling()[0];
}
示例14: enableLogging
/**
* Les logs ne sont pas enregistrés lors des tests avec PHPUnit.
* Cette méthode permet de les réactiver.
* @see http://www.yiiframework.com/wiki/271/how-to-re-enable-logging-during-unit-testing/
*/
public static function enableLogging()
{
// automatically send every new message to available log routes
Yii::getLogger()->autoFlush = 1;
// when sending a message to log routes, also notify them to dump the message
// into the corresponding persistent storage (e.g. DB, email)
Yii::getLogger()->autoDump = true;
}
示例15: testMiddleware
public function testMiddleware()
{
\Yii::getLogger()->flush();
$this->commandBus->addMiddleware(new TestMiddleware());
$result = $this->commandBus->handle(new TestCommand());
$this->assertEquals('test ok', $result);
$this->assertNotFalse(array_search('middleware test 1 ok', \Yii::$app->getLog()->logger->messages[1]));
$this->assertNotFalse(array_search('middleware test 2 ok', \Yii::$app->getLog()->logger->messages[2]));
}