24use DebugBar\DataCollector\MessagesCollector;
42 protected $maxnboflines;
59 parent::__construct($name);
62 $this->maxnboflines =
getDolGlobalInt(
'DEBUGBAR_LOGS_LINES_NUMBER', 250);
76 $title = $langs->transnoentities(
'Logs');
77 $name = $this->getName();
82 "widget" =>
"PhpDebugBar.Widgets.MessagesWidget",
83 "map" =>
"$name.messages",
86 "$title:badge" => array(
87 "map" =>
"$name.count",
109 foreach ($conf->logbuffer as $line) {
110 if ($this->nboflines >= $this->maxnboflines) {
113 foreach ($log_levels as $level_key => $level) {
114 if (strpos(strtolower($line), strtolower($level_key)) == 20) {
116 $this->addMessage($line, $level,
false);
122 return parent::collect();
133 $path = DOL_DATA_ROOT.
'/dolibarr.log';
145 if (!file_exists($path)) {
150 $file = implode(
"", $this->
tailFile($path, $this->maxnboflines));
152 foreach ($this->
getLogs($file) as $log) {
153 $this->addMessage($log[
'line'], $log[
'level'],
false);
166 $handle = fopen($file,
"r");
167 $linecounter = $lines;
171 while ($linecounter > 0) {
174 if (fseek($handle, $pos, SEEK_END) == -1) {
185 $text[$lines - $linecounter - 1] = fgets($handle);
191 return array_reverse($text);
202 $pattern =
"/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.*/";
204 preg_match_all($pattern, $file, $matches);
206 foreach ($matches as $lines) {
207 foreach ($lines as $line) {
208 foreach ($log_levels as $level_key => $level) {
209 if (strpos(strtolower($line), strtolower($level_key)) == 20) {
210 $log[] = array(
'level' => $level,
'line' => $line);
215 $log = array_reverse($log);
226 $class =
new ReflectionClass(
new LogLevel());
227 $levels = $class->getConstants();
228 $levels[
'ERR'] =
'error';
229 $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.
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 dolibarr global constant int value.