PluginProbe
Search Atlas SEO – OTTO AI SEO Automation for WordPress / 2.6.21
Search Atlas SEO – OTTO AI SEO Automation for WordPress v2.6.21
2.6.26 2.6.25 2.6.24 2.6.23 2.6.22 2.6.21 2.6.20 2.6.19 2.6.18 2.6.17 2.6.16 2.6.15 2.6.14 2.6.13 2.6.12 2.6.11 2.6.10 2.6.9 2.6.8 2.6.7 2.6.6 2.6.5 2.6.4 2.6.3 2.5.23 All 138 releases
metasync / includes / class-metasync-errorlogs.php

class-metasync-errorlogs.php in Search Atlas SEO – OTTO AI SEO Automation for WordPress 2.6.21, at includes/class-metasync-errorlogs.php

112 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 class ErrorLog {
3 private $logFilePath;
4
5 /**
6 * ErrorLog constructor.
7 *
8 * @param string $logFilePath
9 */
10 public function __construct() {
11 $this->logFilePath = ini_get('error_log');
12 }
13
14 public function getParsedLogFile() {
15 $parsedLogs = [];
16 $logFileHandle = explode("\n", file_get_contents($this->logFilePath));
17
18 foreach ($logFileHandle as $id => $currentLine) {
19 // Normal error log line starts with the date & time in []
20 if ('[' === @$currentLine[0]) {
21 // if (10000 === \count($parsedLogs)) {
22 // return $parsedLogs;
23 // }
24
25 // Get the datetime when the error occurred and convert it to berlin timezone
26 try {
27 $dateArr = [];
28 preg_match('~^\[(.*?)\]~', $currentLine, $dateArr);
29 $currentLine = str_replace($dateArr[0], '', $currentLine);
30 $currentLine = trim($currentLine);
31 $errorDateTime = new DateTime($dateArr[1]);
32 $errorDateTime->setTimezone(new DateTimeZone('Europe/Berlin'));
33 $errorDateTime = $errorDateTime->format('Y-m-d H:i:s');
34 } catch (\Exception $e) {
35 $errorDateTime = '';
36 }
37
38 // Get the type of the error
39 if (false !== strpos($currentLine, 'PHP Warning')) {
40 $currentLine = str_replace('PHP Warning:', '', $currentLine);
41 $currentLine = trim($currentLine);
42 $errorType = 'WARNING';
43 } else if (false !== strpos($currentLine, 'PHP Notice')) {
44 $currentLine = str_replace('PHP Notice:', '', $currentLine);
45 $currentLine = trim($currentLine);
46 $errorType = 'NOTICE';
47 } else if (false !== strpos($currentLine, 'PHP Fatal error')) {
48 $currentLine = str_replace('PHP Fatal error:', '', $currentLine);
49 $currentLine = trim($currentLine);
50 $errorType = 'FATAL';
51 } else if (false !== strpos($currentLine, 'PHP Parse error')) {
52 $currentLine = str_replace('PHP Parse error:', '', $currentLine);
53 $currentLine = trim($currentLine);
54 $errorType = 'SYNTAX';
55 } else if (false !== strpos($currentLine, 'PHP Exception')) {
56 $currentLine = str_replace('PHP Exception:', '', $currentLine);
57 $currentLine = trim($currentLine);
58 $errorType = 'EXCEPTION';
59 } else {
60 $errorType = 'UNKNOWN';
61 }
62
63 if (false !== strpos($currentLine, ' on line ')) {
64 $errorLine = explode(' on line ', $currentLine);
65 $errorLine = trim($errorLine[1]);
66 $currentLine = str_replace(' on line ' . $errorLine, '', $currentLine);
67 } else {
68 $errorLine = substr($currentLine, strrpos($currentLine, ':') + 1);
69 $currentLine = str_replace(':' . $errorLine, '', $currentLine);
70 }
71
72 $errorFile = explode(' in /', $currentLine);
73 $errorFile = '/' . trim($errorFile[1]);
74 $currentLine = str_replace(' in ' . $errorFile, '', $currentLine);
75
76 // The message of the error
77 $errorMessage = trim($currentLine);
78
79 $parsedLogs[] = [
80 'id' => $id+1,
81 'dateTime' => $errorDateTime,
82 'type' => $errorType,
83 'file' => $errorFile,
84 'line' => (int)$errorLine,
85 'message' => $errorMessage,
86 'stackTrace' => []
87 ];
88 } // Stack trace beginning line
89 else if ('Stack trace:' === $currentLine) {
90 $stackTraceLineNumber = 0;
91
92 foreach ($logFileHandle as $line) {
93 $currentLine = str_replace(PHP_EOL, '', $line);
94
95 // If the current line is a stack trace line
96 if ('#' === $currentLine[0]) {
97 $parsedLogsLastKey = key($parsedLogs);
98 $currentLine = str_replace('#' . $stackTraceLineNumber, '', $currentLine);
99 $parsedLogs[$parsedLogsLastKey]['stackTrace'][] = trim($currentLine);
100
101 $stackTraceLineNumber++;
102 } // If the current line is the last stack trace ('thrown in...')
103 else {
104 break;
105 }
106 }
107 }
108 }
109
110 return $parsedLogs;
111 }
112 }