Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 21 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
OlzLogsChannel | |
0.00% |
0 / 21 |
|
0.00% |
0 / 5 |
56 | |
0.00% |
0 / 1 |
getId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getRetentionDays | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getLogFileForDateTime | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 | |||
getDateTimeForFilePath | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace Olz\Apps\Logs\Utils; |
4 | |
5 | use Olz\Utils\WithUtilsTrait; |
6 | |
7 | class OlzLogsChannel extends DailyFileLogsChannel { |
8 | use WithUtilsTrait; |
9 | |
10 | public static function getId(): string { |
11 | return 'olz-logs'; |
12 | } |
13 | |
14 | public static function getName(): string { |
15 | return "OLZ Logs"; |
16 | } |
17 | |
18 | protected function getRetentionDays(): ?int { |
19 | return 366; |
20 | } |
21 | |
22 | protected function getLogFileForDateTime(\DateTime $datetime): LogFileInterface { |
23 | $private_path = $this->envUtils()->getPrivatePath(); |
24 | $logs_path = "{$private_path}logs/"; |
25 | $iso_date = $datetime->format('Y-m-d'); |
26 | $plain_path = "{$logs_path}merged-{$iso_date}.log"; |
27 | $gz_path = "{$plain_path}.gz"; |
28 | $iso_today = $this->dateUtils()->getIsoToday(); |
29 | if ($iso_date < $iso_today) { |
30 | return new HybridLogFile($gz_path, $plain_path, $plain_path); |
31 | } |
32 | return new PlainLogFile($plain_path, $plain_path); |
33 | } |
34 | |
35 | protected function getDateTimeForFilePath(string $file_path): \DateTime { |
36 | $private_path = $this->envUtils()->getPrivatePath(); |
37 | $logs_path = "{$private_path}logs/"; |
38 | $esc_logs_path = preg_quote($logs_path, '/'); |
39 | $pattern = "/^{$esc_logs_path}merged\\-(\\d{4}\\-\\d{2}\\-\\d{2})\\.log(\\.gz)?$/"; |
40 | $res = preg_match($pattern, $file_path, $matches); |
41 | if (!$res) { |
42 | throw new \Exception("Not an OLZ Log file path: {$file_path}"); |
43 | } |
44 | $iso_date = $matches[1]; |
45 | return new \DateTime($iso_date); |
46 | } |
47 | } |