|
34 | 34 | }); |
35 | 35 |
|
36 | 36 | it('extracts JSON from the log text', function () { |
| 37 | + config(['log-viewer.strip_extracted_context' => true]); |
37 | 38 | $logText = <<<'EOF' |
38 | 39 | Example log entry for the level debug |
39 | 40 | with multiple lines of content. |
40 | | -{"one":1,"two":"two","three":[1,2,3]} |
| 41 | + {"one":1,"two":"two","three":[1,2,3]} |
41 | 42 | can contain dumped objects or JSON as well - it's all part of the contents. |
42 | 43 | EOF; |
43 | 44 | $jsonString = '{"one":1,"two":"two","three":[1,2,3]}'; |
|
50 | 51 | assertEquals(json_decode($jsonString, true), $log->contexts[0]); |
51 | 52 | }); |
52 | 53 |
|
| 54 | +it('extracts JSON, but does not remove from the log text if the config is set to false', function () { |
| 55 | + config(['log-viewer.strip_extracted_context' => false]); |
| 56 | + $logText = <<<'EOF' |
| 57 | +Example log entry for the level debug |
| 58 | +with multiple lines of content. |
| 59 | + {"one":1,"two":"two","three":[1,2,3]} |
| 60 | +can contain dumped objects or JSON as well - it's all part of the contents. |
| 61 | +EOF; |
| 62 | + $text = '[2022-08-25 11:16:17] local.DEBUG: '.$logText; |
| 63 | + |
| 64 | + $log = new Log(0, $text, 'laravel.log', 0); |
| 65 | + |
| 66 | + assertEquals('Example log entry for the level debug', $log->text); |
| 67 | + assertEquals($logText, $log->fullText); |
| 68 | + assertEquals(json_decode('{"one":1,"two":"two","three":[1,2,3]}', true), $log->contexts[0]); |
| 69 | +}); |
| 70 | + |
| 71 | +it('extracts JSON from a complex log', function () { |
| 72 | + config(['log-viewer.strip_extracted_context' => true]); |
| 73 | + $logText = <<<'EOF' |
| 74 | +Initiating facebook login. |
| 75 | +[HTTP request] |
| 76 | +*User ID:* guest |
| 77 | +*Request:* GET https://system.test/book/arunas/submit-facebook |
| 78 | +*Agent:* Mozilla/5.0 (iPhone; CPU iPhone OS 15_6_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/19G82 [FBAN/FBIOS;FBDV/iPhone9,3;FBMD/iPhone;FBSN/iOS;FBSV/15.6.1;FBSS/2;FBID/phone;FBLC/da_DK;FBOP/5] |
| 79 | + {"permalink":"arunas","session":{"_token":"BpqyiNyinnLamzer4jqzrh9NTyC6emFR41FitMpv","_previous":{"url":"https://system.test/book/arunas/center"},"_flash":{"old":[],"new":[]},"latest_permalink":"arunas"},"ip":"127.0.0.1","user_agent":"Mozilla/5.0 (iPhone; CPU iPhone OS 15_6_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/19G82 [FBAN/FBIOS;FBDV/iPhone9,3;FBMD/iPhone;FBSN/iOS;FBSV/15.6.1;FBSS/2;FBID/phone;FBLC/da_DK;FBOP/5]"} |
| 80 | +EOF; |
| 81 | + |
| 82 | + $jsonString = '{"permalink":"arunas","session":{"_token":"BpqyiNyinnLamzer4jqzrh9NTyC6emFR41FitMpv","_previous":{"url":"https://system.test/book/arunas/center"},"_flash":{"old":[],"new":[]},"latest_permalink":"arunas"},"ip":"127.0.0.1","user_agent":"Mozilla/5.0 (iPhone; CPU iPhone OS 15_6_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/19G82 [FBAN/FBIOS;FBDV/iPhone9,3;FBMD/iPhone;FBSN/iOS;FBSV/15.6.1;FBSS/2;FBID/phone;FBLC/da_DK;FBOP/5]"}'; |
| 83 | + $text = '[2022-08-25 11:16:17] local.DEBUG: '.$logText; |
| 84 | + |
| 85 | + $log = new Log(0, $text, 'laravel.log', 0); |
| 86 | + |
| 87 | + assertEquals('arunas', $log->contexts[0]['permalink'] ?? null); |
| 88 | + assertEquals('Initiating facebook login.', $log->text); |
| 89 | + assertEquals(str_replace($jsonString, '', $logText), $log->fullText); |
| 90 | + assertEquals(json_decode($jsonString, true), $log->contexts[0]); |
| 91 | +}); |
| 92 | + |
53 | 93 | it('can understand the optional microseconds in the timestamp', function () { |
54 | 94 | $text = '[2022-08-25 11:16:17.125000] local.DEBUG: Example log entry for the level debug'; |
55 | 95 |
|
|
0 commit comments