detail.php 1.76 KB
Newer Older
Mark committed
1 2 3 4 5 6 7 8 9 10 11 12
<?php
use yii\helpers\Html;
use yii\grid\GridView;
use yii\data\ArrayDataProvider;
use yii\log\Logger;
?>
<h1>Log Messages</h1>
<?php

echo GridView::widget([
	'dataProvider' => $dataProvider,
	'id' => 'log-panel-detailed-grid',
13
	'options' => ['class' => 'detail-grid-view'],
Mark committed
14 15
	'filterModel' => $searchModel,
	'filterUrl' => $panel->getUrl(),
Mark committed
16
	'rowOptions' => function ($model, $key, $index, $grid) {
Mark committed
17 18 19 20 21 22 23 24 25 26 27
		switch($model['level']) {
			case Logger::LEVEL_ERROR : return ['class' => 'danger'];
			case Logger::LEVEL_WARNING : return ['class' => 'warning'];
			case Logger::LEVEL_INFO : return ['class' => 'success'];
			default: return [];
		}
	},
	'columns' => [
		['class' => 'yii\grid\SerialColumn'],
		[
			'attribute' => 'time',
Mark committed
28
			'value' => function ($data) {
Mark committed
29 30 31 32
				$timeInSeconds = $data['time'] / 1000;
				$millisecondsDiff = (int)(($timeInSeconds - (int)$timeInSeconds) * 1000);
				return date('H:i:s.',$timeInSeconds) . sprintf('%03d',$millisecondsDiff);
			},
33 34 35
			'headerOptions' => [
				'class' => 'sort-numerical'
			]
Mark committed
36 37 38
		],
		[
			'attribute' => 'level',
Mark committed
39
			'value' => function ($data) {
Mark committed
40 41 42 43 44
				return Logger::getLevelName($data['level']);
			},
			'filter' => [
				Logger::LEVEL_TRACE => ' Trace ',
				Logger::LEVEL_INFO => ' Info ',
45
				Logger::LEVEL_WARNING => ' Warning ',
Mark committed
46 47 48 49 50 51
				Logger::LEVEL_ERROR => ' Error ',
			],
		],
		'category',
		[
			'attribute' => 'message',
Mark committed
52
			'value' => function ($data) {
Mark committed
53 54 55 56 57
				$message = nl2br(Html::encode($data['message']));

				if (!empty($data['trace'])) {
					$message .= Html::ul($data['trace'], [
						'class' => 'trace',
Mark committed
58
						'item' => function ($trace) {
Mark committed
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
							return "<li>{$trace['file']} ({$trace['line']})</li>";
						}
					]);
				};

				return $message;
			},
			'format' => 'html',
			'options' => [
				'width' => '50%',
			],
		],
	],
]);
?>