Skip to content

Commit

Permalink
Support for displaying CustomLogs in PW Logs panel as interactive dum…
Browse files Browse the repository at this point in the history
…ped array.
  • Loading branch information
adrianbj committed Jul 10, 2024
1 parent c987f23 commit 9627de6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
2 changes: 1 addition & 1 deletion TracyDebugger.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static function getModuleInfo() {
'summary' => __('Tracy debugger from Nette with many PW specific custom tools.', __FILE__),
'author' => 'Adrian Jones',
'href' => 'https://processwire.com/talk/forum/58-tracy-debugger/',
'version' => '4.26.30',
'version' => '4.26.31',
'autoload' => 100000, // in PW 3.0.114+ higher numbers are loaded first - we want Tracy first
'singular' => true,
'requires' => 'ProcessWire>=2.7.2, PHP>=5.4.4',
Expand Down
50 changes: 35 additions & 15 deletions panels/ProcesswireLogsPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,25 @@ public function getTab() {
$errorLogs = array('errors', 'exceptions', 'files-errors');

if($this->wire('modules')->isInstalled('CustomLogs')) {
$custom_logs = $this->wire('modules')->getModuleConfigData('CustomLogs');
$custom_logs = $this->wire('modules')->get('CustomLogs');
$custom_logs_config = $custom_logs->data();
}

foreach($logs as $log) {

if(isset($custom_logs) && array_key_exists($log['name'], $custom_logs['customLogsParsed'])) {
continue;
if(isset($custom_logs) && array_key_exists($log['name'], $custom_logs_config['customLogsParsed'])) {
$isCustom = true;
$lines = $custom_logs->getEntries($log['name']);
}

$lines = \TracyDebugger::tailCustom($this->wire('config')->paths->logs.$log['name'].'.txt', \TracyDebugger::getDataValue("numLogEntries"));
$lines = mb_convert_encoding($lines, 'UTF-8');
$lines = explode("\n", $lines);
foreach($lines as $key => $line) {
$entry = $this->wire('log')->lineToEntry($line);
$lines[$key] = $entry;
else {
$isCustom = false;
$lines = \TracyDebugger::tailCustom($this->wire('config')->paths->logs.$log['name'].'.txt', \TracyDebugger::getDataValue("numLogEntries"));
$lines = mb_convert_encoding($lines, 'UTF-8');
$lines = explode("\n", $lines);
foreach($lines as $key => $line) {
$entry = $this->wire('log')->lineToEntry($line);
$lines[$key] = $entry;
}
}

$x=99;
Expand All @@ -73,14 +77,30 @@ public function getTab() {
$logLines = $logLinesData[$log['name']]['lines'];

foreach($logLines as $entry) {

if(($isCustom && !isset($entry[0])) || (!$isCustom && !isset($entry['date']))) {
continue;
}

$itemKey = $log['name'] . '_' . $x;
$entriesArr[$itemKey]['timestamp'] = @strtotime($entry['date']); // silenced in case timezone is not set
$entriesArr[$itemKey]['timestamp'] = @strtotime($isCustom ? $entry[0] : $entry['date']); // silenced in case timezone is not set
$entriesArr[$itemKey]['linenumber'] = 99-$x;
$entriesArr[$itemKey]['order'] = $itemKey;
$entriesArr[$itemKey]['date'] = $entry['date'];
$entriesArr[$itemKey]['text'] = $entry['text'];
$entriesArr[$itemKey]['user'] = $entry['user'];
$entriesArr[$itemKey]['url'] = "<a href='".$entry['url']."'>".$entry['url']."</a>";
$entriesArr[$itemKey]['date'] = $isCustom ? $entry[0] : $entry['date'];
if($isCustom) {
unset($entry[0]);
$entry = array_values($entry);
$assoc_entry = array();
foreach ($entry as $key => $value) {
if(isset($custom_logs_config['customLogsParsed'][$log['name']][$key])) {
$assoc_entry[str_replace('{url}', '', $custom_logs_config['customLogsParsed'][$log['name']][$key])] = $value;
}
}
$entry = $assoc_entry;
}
$entriesArr[$itemKey]['text'] = $isCustom ? json_encode($entry) : $entry['text'];
$entriesArr[$itemKey]['user'] = $isCustom ? '' : $entry['user'];
$entriesArr[$itemKey]['url'] = $isCustom ? '' : "<a href='".$entry['url']."'>".$entry['url']."</a>";
$entriesArr[$itemKey]['log'] = $log['name'];
$x--;
$this->numLogEntries++;
Expand Down

0 comments on commit 9627de6

Please sign in to comment.