3 use DebugBar\DataCollector\MessagesCollector;
21 protected $maxnboflines;
38 parent::__construct($name);
41 $this->maxnboflines =
getDolGlobalInt(
'DEBUGBAR_LOGS_LINES_NUMBER', 250);
55 $title = $langs->transnoentities(
'Logs');
56 $name = $this->getName();
61 "widget" =>
"PhpDebugBar.Widgets.MessagesWidget",
62 "map" =>
"$name.messages",
65 "$title:badge" => array(
66 "map" =>
"$name.count",
88 foreach ($conf->logbuffer as $line) {
89 if ($this->nboflines >= $this->maxnboflines) {
92 foreach ($log_levels as $level_key => $level) {
93 if (strpos(strtolower($line), strtolower($level_key)) == 20) {
95 $this->addMessage($line, $level,
false);
101 return parent::collect();
112 $path = DOL_DATA_ROOT.
'/dolibarr.log';
124 if (!file_exists($path)) {
129 $file = implode(
"", $this->
tailFile($path, $this->maxnboflines));
131 foreach ($this->
getLogs($file) as $log) {
132 $this->addMessage($log[
'line'], $log[
'level'],
false);
145 $handle = fopen($file,
"r");
146 $linecounter = $lines;
150 while ($linecounter > 0) {
153 if (fseek($handle, $pos, SEEK_END) == -1) {
164 $text[$lines - $linecounter - 1] = fgets($handle);
170 return array_reverse($text);
181 $pattern =
"/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.*/";
183 preg_match_all($pattern, $file, $matches);
185 foreach ($matches as $lines) {
186 foreach ($lines as $line) {
187 foreach ($log_levels as $level_key => $level) {
188 if (strpos(strtolower($line), strtolower($level_key)) == 20) {
189 $log[] = array(
'level' => $level,
'line' => $line);
194 $log = array_reverse($log);
205 $class =
new ReflectionClass(
new LogLevel());
206 $levels = $class->getConstants();
207 $levels[
'ERR'] =
'error';
208 $levels[
'WARN'] =
'warning';