|
8 | 8 |
|
9 | 9 | class Log |
10 | 10 | { |
11 | | - const LOG_CONTENT_PATTERN = '/^\[(\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(\.\d{6}[\+-]\d\d:\d\d)?)\](?:.*?(\w+)\.|.*?)'; |
| 11 | + const LOG_CONTENT_PATTERN = '/^\[(\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}\.?(\d{6}([\+-]\d\d:\d\d)?)?)\](.*?(\w+)\.|.*?)'; |
12 | 12 |
|
13 | 13 | const LOG_CONTENT_PATTERN_2 = ': (.*?)( in [\/].*?:[0-9]+)?$/is'; |
14 | 14 |
|
@@ -54,17 +54,32 @@ public function __construct( |
54 | 54 | $firstLineSplit = str_split($firstLine, 1000); |
55 | 55 | preg_match($pattern, array_shift($firstLineSplit), $matches); |
56 | 56 |
|
57 | | - $this->environment = $matches[3] ?? ''; |
58 | 57 | $this->time = Carbon::parse($matches[1])->tz(config('app.timezone', 'UTC')); |
59 | 58 |
|
60 | 59 | if (! empty($matches[2])) { |
61 | 60 | // we got microseconds! |
62 | 61 | $this->time = $this->time->micros((int) $matches[2]); |
63 | 62 | } |
64 | 63 |
|
65 | | - $firstLineText = $matches[4]; |
| 64 | + if (! empty($matches[3])) { |
| 65 | + // we have a time offset! |
| 66 | + // TODO: handle the offset provided here, which is provided as a string like "+03:00" or "-02:30" |
| 67 | + } |
| 68 | + |
| 69 | + $this->environment = $matches[5] ?? ''; |
| 70 | + |
| 71 | + // There might be something in the middle between the timestamp |
| 72 | + // and the environment/level. Let's put that at the beginning of the first line. |
| 73 | + $middle = trim(rtrim($matches[4] ?? '', $this->environment.'.')); |
| 74 | + |
| 75 | + $firstLineText = $matches[6]; |
| 76 | + |
| 77 | + if (! empty($middle)) { |
| 78 | + $firstLineText = $middle.' '.$firstLineText; |
| 79 | + } |
| 80 | + |
66 | 81 | $this->text = mb_convert_encoding($firstLineText, 'UTF-8', 'UTF-8'); |
67 | | - $text = $firstLineText.($matches[5] ?? '').implode('', $firstLineSplit)."\n".$theRestOfIt; |
| 82 | + $text = $firstLineText.($matches[7] ?? '').implode('', $firstLineSplit)."\n".$theRestOfIt; |
68 | 83 |
|
69 | 84 | if (session()->get('log-viewer:shorter-stack-traces', false)) { |
70 | 85 | $excludes = config('log-viewer.shorter_stack_trace_excludes', []); |
|
0 commit comments