You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
1.9 KiB

12 years ago
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\debug\panels;
use Yii;
use yii\debug\Panel;
12 years ago
use yii\log\Logger;
use yii\debug\models\search\Log;
12 years ago
/**
* Debugger panel that collects and displays logs.
*
12 years ago
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class LogPanel extends Panel
{
/**
* @var array log messages extracted to array as models, to use with data provider.
*/
private $_models ;
12 years ago
public function getName()
{
return 'Logs';
}
public function getSummary()
{
return Yii::$app->view->render('panels/log/summary',['data' => $this->data, 'panel' => $this]);
12 years ago
}
public function getDetail()
{
$searchModel = new Log();
$dataProvider = $searchModel->search($_GET, $this->getModels());
12 years ago
return Yii::$app->view->render('panels/log/detail',[
'dataProvider' => $dataProvider,
'panel' => $this,
'searchModel' => $searchModel,
]);
12 years ago
}
public function save()
{
12 years ago
$target = $this->module->logTarget;
$messages = $target->filterMessages($target->messages, Logger::LEVEL_ERROR | Logger::LEVEL_INFO | Logger::LEVEL_WARNING | Logger::LEVEL_TRACE);
return ['messages' => $messages];
12 years ago
}
/**
* Returns array of models that represents logs of the current request. Can be used with data providers,
* like yii\data\ArrayDataProvider.
* @param boolean $refresh if needed to build models from log messages and refresh them.
* @return array models
*/
protected function getModels($refresh=false)
{
if ($this->_models === null || $refresh) {
$this->_models = [];
foreach($this->data['messages'] as $message) {
$this->_models[] = [
'message' => $message[0],
'level' => $message[1],
'category' => $message[2],
'time' => ($message[3] * 1000), #time in milliseconds
'trace' => $message[4]
];
}
}
return $this->_models;
}
12 years ago
}