Skip to content

Commit 7358e25

Browse files
committed
Enhance log view.
1 parent 480c971 commit 7358e25

1 file changed

Lines changed: 43 additions & 23 deletions

File tree

app/code/community/Kiatng/Shooter/controllers/LogController.php

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,33 +34,49 @@ public function indexAction()
3434
}
3535
}
3636

37-
// Get all log files in var/log.
38-
$paths = glob(Mage::getBaseDir('log') . DS . "*.log");
37+
$paths = [];
38+
// Get the error log file.
3939
if (($path = ini_get('error_log')) && file_exists($path)) {
40-
array_unshift($paths, $path);
40+
$paths[] = $path;
4141
}
42+
// Get all log files in var/log.
43+
$paths += glob(Mage::getBaseDir('log') . DS . "*.log");
4244

43-
// Get the latest error in var/report.
4445
$helper = Mage::helper('shooter/file');
46+
foreach ($paths as $path) {
47+
$url = Mage::getUrl('*/*/tail', ['path' => base64_encode($path), 'lines' => 50]);
48+
if ($secs == -1 || time() - filemtime($path) <= $secs) {
49+
$output .= $helper->getTailHtml($path, $lines);
50+
$output .= "<p><a href='$url'>View More</a></p>";
51+
} else {
52+
$output .= "<h3><a href='$url'>$path</a></h3><p><em>No log in the last $secs seconds (param 'secs')</em></p>";
53+
}
54+
}
55+
56+
// Get the latest error in var/report.
4557
$dir = Mage::getBaseDir('var') . DS . 'report';
4658
if ($latest = $helper->latest($dir)) {
47-
$paths[] = $latest;
59+
$output .= $helper->getTailHtml($latest, 100);
60+
$url = Mage::getUrl('*/*/deleteReport', ['fnm' => basename($latest)]);
61+
$output .= "<p><a href='$url'>Delete Report Permanently</a></p>";
4862
}
4963

50-
foreach ($paths as $path) {
51-
if ($secs == -1 || time() - filemtime($path) <= $secs || strpos($path, 'report')) {
52-
if ($tail = $helper->tail($path, $lines)) {
53-
$tail = print_r($tail, true);
54-
$dt = Mage::getSingleton('core/date')->date('Y-m-d H:i:s', filemtime($path));
55-
$output .= "<h3>$path <em>$dt</em></h3><pre>$tail</pre>";
56-
}
57-
} elseif (preg_match('/(exception|system|shooter)\.log$/', $path)) {
58-
$output .= "<h3>$path</h3><p><em>No log in the last $secs seconds (param 'secs')</em></p>";
59-
}
60-
}
6164
$this->getResponse()->setHeader('Content-Type', 'text/html')->setBody($output);
6265
}
6366

67+
/**
68+
* Delete the report file.
69+
*/
70+
public function deleteReportAction()
71+
{
72+
$filename = $this->getRequest()->getParam('fnm');
73+
$path = Mage::getBaseDir('var') . DS . 'report' . DS . $filename;
74+
if (file_exists($path)) {
75+
unlink($path);
76+
}
77+
$this->_redirectReferer();
78+
}
79+
6480
/**
6581
* Clear the last error flag.
6682
*/
@@ -80,15 +96,19 @@ public function clearLastErrorAction()
8096
*/
8197
public function tailAction()
8298
{
83-
$fnm = $this->getRequest()->getParam('fnm', 'exception.log');
84-
$dir = $this->getRequest()->getParam('dir', 'log');
8599
$lines = $this->getRequest()->getParam('lines', 80);
86-
87-
if (!str_contains($dir, '/')) {
88-
/** @see Mage_Core_Model_Config_Options for all the values of $dir */
89-
$dir = Mage::getBaseDir($dir);
100+
$path = $this->getRequest()->getParam('path');
101+
if ($path) {
102+
$paths = [base64_decode($path)];
103+
} else {
104+
$fnm = $this->getRequest()->getParam('fnm', 'exception.log');
105+
$dir = $this->getRequest()->getParam('dir', 'log');
106+
if (!str_contains($dir, '/')) {
107+
/** @see Mage_Core_Model_Config_Options for all the values of $dir */
108+
$dir = Mage::getBaseDir($dir);
109+
}
110+
$paths = glob($dir . DS . $fnm);
90111
}
91-
$paths = glob($dir . DS . $fnm);
92112
$output = '<h2>GMT '.Mage::getSingleton('core/date')->gmtDate().'</h2>';
93113

94114
$helper = Mage::helper('shooter/file');

0 commit comments

Comments
 (0)