24use DebugBar\DataCollector\MessagesCollector;
42 protected $maxnboflines;
57 parent::__construct($name);
60 $this->maxnboflines =
getDolGlobalInt(
'DEBUGBAR_LOGS_LINES_NUMBER', 250);
74 $title = $langs->transnoentities(
'Logs');
75 $name = $this->getName();
80 "widget" =>
"PhpDebugBar.Widgets.MessagesWidget",
81 "map" =>
"$name.messages",
84 "$title:badge" => array(
85 "map" =>
"$name.count",
107 foreach ($conf->logbuffer as $line) {
108 if ($this->nboflines >= $this->maxnboflines) {
111 foreach ($log_levels as $level_key => $level) {
112 if (strpos(strtolower($line), strtolower($level_key)) == 20) {
114 $this->addMessage($line, $level,
false);
120 return parent::collect();
131 $path = DOL_DATA_ROOT.
'/dolibarr.log';
143 if (!file_exists($path)) {
148 $file = implode(
"", $this->
tailFile($path, $this->maxnboflines));
150 foreach ($this->
getLogs($file) as $log) {
151 $this->addMessage($log[
'line'], $log[
'level'],
false);
164 $handle = fopen($file,
"r");
165 $linecounter = $lines;
169 while ($linecounter > 0) {
172 if (fseek($handle, $pos, SEEK_END) == -1) {
183 $text[$lines - $linecounter - 1] = fgets($handle);
189 return array_reverse($text);
200 $pattern =
"/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.*/";
203 preg_match_all($pattern, $file, $matches);
205 foreach ($matches as $lines) {
206 foreach ($lines as $line) {
207 foreach ($log_levels as $level_key => $level) {
208 if (strpos(strtolower($line), strtolower($level_key)) == 20) {
209 $log[] = array(
'level' => $level,
'line' => $line);
214 $log = array_reverse($log);
225 $class =
new ReflectionClass(
new LogLevel());
226 $levels = $class->getConstants();
227 $levels[
'ERR'] =
'error';
228 $levels[
'WARN'] =
'warning';
getWidgets()
Return widget settings.
getStorageLogs($path)
Get logs.
__construct($path=null, $name='logs')
Constructor.
getLogs($file)
Search a string for log entries into the log file.
getLevels()
Get the log levels from psr/log.
getLogsFile()
Get the path to the logs file.
tailFile($file, $lines)
Get latest file lines.
collect()
Return collected data.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.