Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 22
0.00% covered (danger)
0.00%
0 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
OlzLogsChannel
0.00% covered (danger)
0.00%
0 / 22
0.00% covered (danger)
0.00%
0 / 5
56
0.00% covered (danger)
0.00%
0 / 1
 getId
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getName
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getRetentionDays
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getLogFileForDateTime
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
6
 getDateTimeForFilePath
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3namespace Olz\Apps\Logs\Utils;
4
5use Olz\Utils\WithUtilsTrait;
6
7class 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        $index_path = "{$plain_path}.index.json.gz";
29        $iso_today = $this->dateUtils()->getIsoToday();
30        if ($iso_date < $iso_today) {
31            return new HybridLogFile($gz_path, $plain_path, $index_path);
32        }
33        return new PlainLogFile($plain_path, $index_path);
34    }
35
36    protected function getDateTimeForFilePath(string $file_path): \DateTime {
37        $private_path = $this->envUtils()->getPrivatePath();
38        $logs_path = "{$private_path}logs/";
39        $esc_logs_path = preg_quote($logs_path, '/');
40        $pattern = "/^{$esc_logs_path}merged\\-(\\d{4}\\-\\d{2}\\-\\d{2})\\.log(\\.gz)?$/";
41        $res = preg_match($pattern, $file_path, $matches);
42        if (!$res) {
43            throw new \Exception("Not an OLZ Log file path: {$file_path}");
44        }
45        $iso_date = $matches[1];
46        return new \DateTime($iso_date);
47    }
48}