Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
8 / 8 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
MultiFileLogger | |
100.00% |
8 / 8 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
setDestination | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
write | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 |
1 | <?php declare(strict_types=1); |
2 | /* |
3 | * This file is part of Aplus Framework Log Library. |
4 | * |
5 | * (c) Natan Felles <natanfelles@gmail.com> |
6 | * |
7 | * For the full copyright and license information, please view the LICENSE |
8 | * file that was distributed with this source code. |
9 | */ |
10 | namespace Framework\Log\Loggers; |
11 | |
12 | use Framework\Log\Log; |
13 | use Framework\Log\Logger; |
14 | use InvalidArgumentException; |
15 | |
16 | /** |
17 | * Class MultiFileLogger. |
18 | * |
19 | * @package log |
20 | */ |
21 | class MultiFileLogger extends Logger |
22 | { |
23 | protected function setDestination(string $destination) : static |
24 | { |
25 | $directory = \realpath($destination); |
26 | if ( ! $directory || ! \is_dir($directory)) { |
27 | throw new InvalidArgumentException('Invalid directory destination: ' . $destination); |
28 | } |
29 | $this->destination = $directory . \DIRECTORY_SEPARATOR; |
30 | return $this; |
31 | } |
32 | |
33 | protected function write(Log $log) : bool |
34 | { |
35 | $filename = $this->getDestination() . \date('Y-m-d', $log->time) . '.log'; |
36 | $eol = $this->getConfig()['eol'] ?? \PHP_EOL . \PHP_EOL; |
37 | return \error_log($log . $eol, 3, $filename); |
38 | } |
39 | } |