|
43 | 43 | ->and($log->context['request'])->toBe(null)
|
44 | 44 | ->and($log->context['host'])->toBe(null);
|
45 | 45 | });
|
| 46 | + |
| 47 | +it('can parse multiline nginx log entries', function () { |
| 48 | + $file = new \Opcodes\LogViewer\LogFile(__DIR__.'/Fixtures/multiline_nginx_error_dummy.log'); |
| 49 | + $file->logs()->scan(); |
| 50 | + |
| 51 | + $logs = $file->logs()->get(); |
| 52 | + |
| 53 | + expect($logs)->toHaveCount(2); |
| 54 | + |
| 55 | + /** @var HttpNginxErrorLog $firstLog */ |
| 56 | + $firstLog = $logs[0]; |
| 57 | + |
| 58 | + // 2024/08/21 09:08:18 [error] 2761052#2761052: *84719 upstream sent too big header while reading response header from upstream, |
| 59 | + // client: 123.123.123.123, server: xxx, request: "GET /api/xx/yy/zz?lang=de HTTP/2.0", |
| 60 | + // upstream: "fastcgi://unix:/var/run/php/php8.1-fpm.sock:", host: "xxx", referrer: "http://some-ip:3000/" |
| 61 | + expect($firstLog->index)->toBe(0) |
| 62 | + ->and($firstLog)->toBeInstanceOf(HttpNginxErrorLog::class) |
| 63 | + ->and($firstLog->datetime->toDateTimeString())->toBe('2024-08-21 09:08:18') |
| 64 | + ->and($firstLog->level)->toBe('error') |
| 65 | + ->and($firstLog->message)->toBe('*84719 upstream sent too big header while reading response header from upstream') |
| 66 | + ->and($firstLog->context['client'])->toBe('123.123.123.123') |
| 67 | + ->and($firstLog->context['server'])->toBe('xxx') |
| 68 | + ->and($firstLog->context['request'])->toBe('GET /api/xx/yy/zz?lang=de HTTP/2.0') |
| 69 | + ->and($firstLog->context['upstream'])->toBe('fastcgi://unix:/var/run/php/php8.1-fpm.sock:') |
| 70 | + ->and($firstLog->context['host'])->toBe('xxx') |
| 71 | + ->and($firstLog->context['referrer'])->toBe('http://some-ip:3000/'); |
| 72 | + |
| 73 | + $secondLog = $logs[1]; |
| 74 | + |
| 75 | + expect($secondLog->index)->toBe(1) |
| 76 | + ->and($secondLog)->toBeInstanceOf(HttpNginxErrorLog::class) |
| 77 | + ->and($secondLog->datetime->toDateTimeString())->toBe('2024-08-21 09:08:19') |
| 78 | + ->and($secondLog->level)->toBe('error') |
| 79 | + ->and($secondLog->message)->toBe(<<<'EOF' |
| 80 | +*84719 FastCGI sent in stderr: "PHP message: [2024-08-21 11:08:18] develop.DEBUG: ActivityService: some message |
| 81 | +PHP message: [2024-08-21 11:08:18] develop.DEBUG: ActivityService: another message |
| 82 | +PHP message: [2024-08-21 11:08:18] develop.DEBUG: ActivityService: blabla: [{"id":308363,"lat":"xx","lng":"yy"}] |
| 83 | +PHP message: [2024-08-21 11:08:18] develop.INFO: provider Payload: {"attr1":"t","attr2":14400,"sources":[{"id":"source","lat":xx,"lng":yy,"tm":{"t":{"maxT":2},"c":{"":""}}}],"t":[{"id":308363,"lat":"xx","lng":"yy"}],"g_s_client":false,"reversed":false,"polygon":{"id":4326},"pathSerializer":"g"} |
| 84 | +PHP message: [2024-08-21 11:08:18] develop.DEBUG: Sending request to final Url (V1) https://someurl/path/v1/endpoint?param=*** |
| 85 | +EOF); |
| 86 | + |
| 87 | +}); |
0 commit comments