3 * @copyright Copyright (C) 2010-2023, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Test\src\Object\Log;
24 use Friendica\Object\Log\ParsedLogLine;
25 use PHPUnit\Framework\TestCase;
28 * Log parser testing class
30 class ParsedLogLineTest extends TestCase
32 public static function do_log_line($logline, $expected_data)
34 $parsed = new ParsedLogLine(0, $logline);
35 foreach ($expected_data as $k => $v) {
36 self::assertSame($parsed->$k, $v, '"'.$k.'" does not match expectation');
41 * test parsing a generic log line
43 public function testGenericLogLine()
46 '2021-05-24T15:40:01Z worker [WARNING]: Spool file does does not start with "item-" {"file":".","worker_id":"560c8b6","worker_cmd":"SpoolPost"} - {"file":"SpoolPost.php","line":40,"function":"execute","uid":"fd8c37","process_id":20846}',
48 'date' => '2021-05-24T15:40:01Z',
49 'context' => 'worker',
51 'message' => 'Spool file does does not start with "item-"',
52 'data' => '{"file":".","worker_id":"560c8b6","worker_cmd":"SpoolPost"}',
53 'source' => '{"file":"SpoolPost.php","line":40,"function":"execute","uid":"fd8c37","process_id":20846}',
59 * test parsing a log line with empty data
61 public function testEmptyDataLogLine()
64 '2021-05-24T15:23:58Z index [INFO]: No HTTP_SIGNATURE header [] - {"file":"HTTPSignature.php","line":476,"function":"getSigner","uid":"0a3934","process_id":14826}',
66 'date' => '2021-05-24T15:23:58Z',
69 'message' => 'No HTTP_SIGNATURE header',
71 'source' => '{"file":"HTTPSignature.php","line":476,"function":"getSigner","uid":"0a3934","process_id":14826}',
77 * test parsing a log line with various " - " in it
79 public function testTrickyDashLogLine()
82 '2021-05-24T15:30:01Z worker [NOTICE]: Load: 0.01/20 - processes: 0/1/6 (0:0, 30:1) - maximum: 10/10 {"worker_id":"ece8fc8","worker_cmd":"Cron"} - {"file":"Worker.php","line":786,"function":"tooMuchWorkers","uid":"364d3c","process_id":20754}',
84 'date' => '2021-05-24T15:30:01Z',
85 'context' => 'worker',
87 'message' => 'Load: 0.01/20 - processes: 0/1/6 (0:0, 30:1) - maximum: 10/10',
88 'data' => '{"worker_id":"ece8fc8","worker_cmd":"Cron"}',
89 'source' => '{"file":"Worker.php","line":786,"function":"tooMuchWorkers","uid":"364d3c","process_id":20754}',
95 * test non conforming log line
97 public function testNonConformingLogLine()
100 'this log line is not formatted as expected',
105 'message' => 'this log line is not formatted as expected',
113 * test missing source
115 public function testMissingSource()
118 '2021-05-24T15:30:01Z worker [NOTICE]: Load: 0.01/20 - processes: 0/1/6 (0:0, 30:1) - maximum: 10/10 {"worker_id":"ece8fc8","worker_cmd":"Cron"}',
120 'date' => '2021-05-24T15:30:01Z',
121 'context' => 'worker',
123 'message' => 'Load: 0.01/20 - processes: 0/1/6 (0:0, 30:1) - maximum: 10/10',
124 'data' => '{"worker_id":"ece8fc8","worker_cmd":"Cron"}',
133 public function testMissingData()
136 '2021-05-24T15:30:01Z worker [NOTICE]: Load: 0.01/20 - processes: 0/1/6 (0:0, 30:1) - maximum: 10/10 - {"file":"Worker.php","line":786,"function":"tooMuchWorkers","uid":"364d3c","process_id":20754}',
138 'date' => '2021-05-24T15:30:01Z',
139 'context' => 'worker',
141 'message' => 'Load: 0.01/20 - processes: 0/1/6 (0:0, 30:1) - maximum: 10/10',
143 'source' => '{"file":"Worker.php","line":786,"function":"tooMuchWorkers","uid":"364d3c","process_id":20754}',
149 * test missing data and source
151 public function testMissingDataAndSource()
154 '2021-05-24T15:30:01Z worker [NOTICE]: Load: 0.01/20 - processes: 0/1/6 (0:0, 30:1) - maximum: 10/10',
156 'date' => '2021-05-24T15:30:01Z',
157 'context' => 'worker',
159 'message' => 'Load: 0.01/20 - processes: 0/1/6 (0:0, 30:1) - maximum: 10/10',
167 * test missing source and invalid data
169 public function testMissingSourceAndInvalidData()
172 '2021-05-24T15:30:01Z worker [NOTICE]: Load: 0.01/20 - processes: 0/1/6 (0:0, 30:1) - maximum: 10/10 {"invalidjson {really',
174 'date' => '2021-05-24T15:30:01Z',
175 'context' => 'worker',
177 'message' => 'Load: 0.01/20 - processes: 0/1/6 (0:0, 30:1) - maximum: 10/10 {"invalidjson {really',