|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
-
-
- namespace yii\debug\panels;
-
- use Yii;
- use yii\debug\Panel;
- use yii\log\Logger;
- use yii\debug\models\search\Log;
-
-
- class LogPanel extends Panel
- {
-
-
- private $_models;
-
-
-
-
- public function getName()
- {
- return 'Logs';
- }
-
-
-
- public function getSummary()
- {
- return Yii::$app->view->render('panels/log/summary', ['data' => $this->data, 'panel' => $this]);
- }
-
-
-
- public function getDetail()
- {
- $searchModel = new Log();
- $dataProvider = $searchModel->search(Yii::$app->request->getQueryParams(), $this->getModels());
-
- return Yii::$app->view->render('panels/log/detail', [
- 'dataProvider' => $dataProvider,
- 'panel' => $this,
- 'searchModel' => $searchModel,
- ]);
- }
-
-
-
- public function save()
- {
- $target = $this->module->logTarget;
- $messages = $target->filterMessages($target->messages, Logger::LEVEL_ERROR | Logger::LEVEL_INFO | Logger::LEVEL_WARNING | Logger::LEVEL_TRACE);
- foreach($messages as &$message) {
-
- if ($message[0] instanceof \Throwable || $message[0] instanceof \Exception) {
- $message[0] = (string) $message[0];
- }
- }
- return ['messages' => $messages];
- }
-
-
-
- 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),
- 'trace' => $message[4]
- ];
- }
- }
-
- return $this->_models;
- }
- }
|