25use DebugBar\DataCollector\MessagesCollector;
43 protected $maxnboflines;
58 parent::__construct($name);
61 $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) {
117 $this->addMessage($line, $level,
false);
123 return parent::collect();
134 $path = DOL_DATA_ROOT.
'/dolibarr.log';
146 if (!file_exists($path)) {
151 $file = implode(
"", $this->
tailFile($path, $this->maxnboflines));
153 foreach ($this->
getLogs($file) as $log) {
154 $this->addMessage($log[
'line'], $log[
'level'],
false);
167 $handle = fopen($file,
"r");
168 $linecounter = $lines;
172 while ($linecounter > 0) {
175 if (fseek($handle, $pos, SEEK_END) == -1) {
186 $text[$lines - $linecounter - 1] = fgets($handle);
192 return array_reverse($text);
203 $pattern =
"/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.*/";
206 preg_match_all($pattern, $file, $matches);
208 foreach ($matches as $lines) {
209 foreach ($lines as $line) {
210 foreach ($log_levels as $level_key => $level) {
211 if (strpos(strtolower($line), strtolower($level_key)) == 20) {
212 $log[] = array(
'level' => $level,
'line' => $line);
217 $log = array_reverse($log);
229 $class =
new ReflectionClass(
new LogLevel());
230 $levels = $class->getConstants();
231 $levels[
'ERR'] =
'error';
232 $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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...