3 use DebugBar\DataCollector\MessagesCollector;
20 protected $maxnboflines;
32 parent::__construct($name);
35 $this->maxnboflines = empty($conf->global->DEBUGBAR_LOGS_LINES_NUMBER) ? 250 : $conf->global->DEBUGBAR_LOGS_LINES_NUMBER;
49 $title = $langs->transnoentities(
'Logs');
50 $name = $this->getName();
55 "widget" =>
"PhpDebugBar.Widgets.MessagesWidget",
56 "map" =>
"$name.messages",
59 "$title:badge" => array(
60 "map" =>
"$name.count",
75 $uselogfile = $conf->global->DEBUGBAR_USE_LOGFILE;
83 foreach ($conf->logbuffer as $line) {
84 if ($this->nboflines >= $this->maxnboflines)
88 foreach ($log_levels as $level_key => $level) {
89 if (strpos(strtolower($line), strtolower($level_key)) == 20) {
91 $this->addMessage($line, $level,
false);
97 return parent::collect();
108 $path = DOL_DATA_ROOT.
'/dolibarr.log';
120 if (!file_exists($path)) {
125 $file = implode(
"", $this->
tailFile($path, $this->maxnboflines));
127 foreach ($this->
getLogs($file) as $log) {
128 $this->addMessage($log[
'line'], $log[
'level'],
false);
141 $handle = fopen($file,
"r");
142 $linecounter = $lines;
146 while ($linecounter > 0) {
149 if (fseek($handle, $pos, SEEK_END) == -1) {
160 $text[$lines - $linecounter - 1] = fgets($handle);
166 return array_reverse($text);
177 $pattern =
"/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.*/";
179 preg_match_all($pattern, $file, $matches);
181 foreach ($matches as $lines) {
182 foreach ($lines as $line) {
183 foreach ($log_levels as $level_key => $level) {
184 if (strpos(strtolower($line), strtolower($level_key)) == 20) {
185 $log[] = array(
'level' => $level,
'line' => $line);
190 $log = array_reverse($log);
201 $class =
new ReflectionClass(
new LogLevel());
202 $levels = $class->getConstants();
203 $levels[
'ERR'] =
'error';
204 $levels[
'WARN'] =
'warning';
getLogsFile()
Get the path to the logs file.
getLogs($file)
Search a string for log entries.
getStorageLogs($path)
Get logs.
collect()
Return collected data.
getWidgets()
Return widget settings.
__construct($path=null, $name= 'logs')
Constructor.
getLevels()
Get the log levels from psr/log.
tailFile($file, $lines)
Get latest file lines.