HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
Yii2LogPanel.php
Go to the documentation of this file.
1 <?php
2 
9 {
10  const CATEGORY_DUMP = 'Yii2Debug.dump';
11 
15  public function init()
16  {
17  $this->_logsEnabled = true;
18  $this->_logsLevels = implode(',', array(
19  CLogger::LEVEL_ERROR,
20  CLogger::LEVEL_INFO,
21  CLogger::LEVEL_WARNING,
22  CLogger::LEVEL_TRACE,
23  ));
24  parent::init();
25  }
26 
27  public function getName()
28  {
29  return 'Logs';
30  }
31 
32  public function getSummary()
33  {
34  $errorCount = 0;
35  $warningCount = 0;
36  $infoCount = 0;
37  foreach ($this->data['messages'] as $log) {
38  $level = $log[1];
39  if ($level == CLogger::LEVEL_ERROR) $errorCount++;
40  elseif ($level == CLogger::LEVEL_WARNING) $warningCount++;
41  elseif ($level == CLogger::LEVEL_INFO) $infoCount++;
42  }
43  return $this->render(dirname(__FILE__) . '/../views/panels/log_bar.php', array(
44  'count' => count($this->data['messages']),
45  'errorCount' => $errorCount,
46  'warningCount' => $warningCount,
47  'infoCount' => $infoCount,
48  ));
49  }
50 
51  public function getDetail()
52  {
53  $data = $this->getData();
54  foreach ($data['messages'] as $i => $log) {
55  list ($message, $level, $category, $time) = $log;
56  $time = date('H:i:s.', $time) . sprintf('%03d', (int)(($time - (int)$time) * 1000));
57  $traces = array();
58  if (($lines = explode("\nStack trace:\n", $message, 2)) !== false) {
59  $message = $lines[0];
60  if (isset($lines[1])) {
61  $traces = array_merge(
62  array('Stack trace:'),
63  explode("\n", $lines[1])
64  );
65  } elseif (($lines = explode("\nin ", $message)) !== false) {
66  $message = array_shift($lines);
67  $base = dirname(Yii::app()->getBasePath()) . DIRECTORY_SEPARATOR;
68  foreach ($lines as &$line) {
69  $line = str_replace($base, '', $line);
70  }
71  unset($line);
72  $traces = $lines;
73  }
74  }
75  $data['messages'][$i] = array($message, $level, $category, $time, $traces);
76  }
77  return $this->render(dirname(__FILE__) . '/../views/panels/log.php', array(
78  'data' => $data,
79  ));
80  }
81 
82  public function save()
83  {
84  return array(
85  'messages' => $this->getLogs(),
86  );
87  }
88 }