Skip to content

Commit 4aaf214

Browse files
authored
feat(LogsCollector): support multiple log files (#1560)
* feat(LogsCollector): support multiple log files * Add log basename to locate the file * Fix daily driver logging
1 parent d861099 commit 4aaf214

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

src/DataCollector/LogsCollector.php

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Barryvdh\Debugbar\DataCollector;
44

55
use DebugBar\DataCollector\MessagesCollector;
6+
use Illuminate\Support\Arr;
67
use Psr\Log\LogLevel;
78
use ReflectionClass;
89

@@ -14,18 +15,14 @@ public function __construct($path = null, $name = 'logs')
1415
{
1516
parent::__construct($name);
1617

17-
$path = $path ?: $this->getLogsFile();
18-
$this->getStorageLogs($path);
19-
}
20-
21-
/**
22-
* Get the path to the logs file
23-
*
24-
* @return string
25-
*/
26-
public function getLogsFile()
27-
{
28-
return storage_path() . '/logs/laravel.log';
18+
$paths = Arr::wrap($path ?: [
19+
storage_path('logs/laravel.log'),
20+
storage_path('logs/laravel-' . date('Y-m-d') . '.log'), // for daily driver
21+
]);
22+
23+
foreach ($paths as $path) {
24+
$this->getStorageLogs($path);
25+
}
2926
}
3027

3128
/**
@@ -44,9 +41,16 @@ public function getStorageLogs($path)
4441

4542
//Load the latest lines, guessing about 15x the number of log entries (for stack traces etc)
4643
$file = implode("", $this->tailFile($path, $this->lines));
44+
$basename = basename($path);
4745

4846
foreach ($this->getLogs($file) as $log) {
49-
$this->addMessage($log['header'] . $log['stack'], $log['level'], false);
47+
$this->messages[] = [
48+
'message' => $log['header'] . $log['stack'],
49+
'label' => $log['level'],
50+
'time' => substr($log['header'], 1, 19),
51+
'collector' => $basename,
52+
'is_string' => false,
53+
];
5054
}
5155
}
5256

@@ -115,11 +119,17 @@ public function getLogs($file)
115119
}
116120
}
117121

118-
$log = array_reverse($log);
119-
120122
return $log;
121123
}
122124

125+
/**
126+
* @return array
127+
*/
128+
public function getMessages()
129+
{
130+
return array_reverse(parent::getMessages());
131+
}
132+
123133
/**
124134
* Get the log levels from psr/log.
125135
* Based on https://github.com/mikemand/logviewer/blob/master/src/Kmd/Logviewer/Logviewer.php by mikemand

src/Resources/laravel-debugbar.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,11 @@ div.phpdebugbar-widgets-messages li.phpdebugbar-widgets-list-item span.phpdebugb
379379
color: #333;
380380
}
381381

382+
div.phpdebugbar-widgets-messages li.phpdebugbar-widgets-list-item span.phpdebugbar-widgets-collector {
383+
text-transform: none;
384+
color: #888;
385+
}
386+
382387
.phpdebugbar-widgets-toolbar i.phpdebugbar-fa.phpdebugbar-fa-search {
383388
position: relative;
384389
top: -1px;

0 commit comments

Comments
 (0)