25use DebugBar\DataCollector\MessagesCollector;
43 protected $maxnboflines;
58 parent::__construct($name);
61 $this->maxnboflines =
getDolGlobalInt(
'DEBUGBAR_LOGS_LINES_NUMBER', 250);
75 $title = $langs->transnoentities(
'Logs');
76 $name = $this->getName();
81 "widget" =>
"PhpDebugBar.Widgets.MessagesWidget",
82 "map" =>
"$name.messages",
85 "$title:badge" => array(
86 "map" =>
"$name.count",
108 foreach ($conf->logbuffer as $line) {
109 if ($this->nboflines >= $this->maxnboflines) {
112 foreach ($log_levels as $level_key => $level) {
113 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}.*/";
205 preg_match_all($pattern, $file, $matches);
207 foreach ($matches as $lines) {
208 foreach ($lines as $line) {
209 foreach ($log_levels as $level_key => $level) {
210 if (strpos(strtolower($line), strtolower($level_key)) == 20) {
211 $log[] = array(
'level' => $level,
'line' => $line);
216 $log = array_reverse($log);
228 $class =
new ReflectionClass(
new LogLevel());
229 $levels = $class->getConstants();
230 $levels[
'ERR'] =
'error';
231 $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.