Skip to content

Commit 7c29eb3

Browse files
authored
Add a decorator logger (#202)
Closes #190
1 parent 3428044 commit 7c29eb3

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

phpstan-src.neon.dist

+4
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ parameters:
66
ignoreErrors:
77
- path: src/ErrorHandler/ResetServiceErrorHandler.php
88
message: '#ResettableContainerInterface#'
9+
10+
# This is due to usages of func_get_args()
11+
- path: src/Logger/DecoratorLogger.php
12+
message: '#Parameter \#1#'

src/Logger/DecoratorLogger.php

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Webmozarts Console Parallelization package.
5+
*
6+
* (c) Webmozarts GmbH <office@webmozarts.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Webmozarts\Console\Parallelization\Logger;
15+
16+
use Throwable;
17+
use Webmozarts\Console\Parallelization\Configuration;
18+
use function func_get_args;
19+
20+
/**
21+
* Base logger that can be extended to override only a few methods of a logger
22+
* and delegate the others to the decorated logger.
23+
*/
24+
abstract class DecoratorLogger implements Logger
25+
{
26+
private Logger $decoratedLogger;
27+
28+
public function __construct(Logger $decoratedLogger)
29+
{
30+
$this->decoratedLogger = $decoratedLogger;
31+
}
32+
33+
public function logConfiguration(
34+
Configuration $configuration,
35+
int $batchSize,
36+
?int $numberOfItems,
37+
string $itemName,
38+
bool $shouldSpawnChildProcesses
39+
): void {
40+
$this->decoratedLogger->logConfiguration(...func_get_args());
41+
}
42+
43+
public function logStart(?int $numberOfItems): void
44+
{
45+
$this->decoratedLogger->logStart(...func_get_args());
46+
}
47+
48+
public function logAdvance(int $steps = 1): void
49+
{
50+
$this->decoratedLogger->logAdvance(...func_get_args());
51+
}
52+
53+
public function logFinish(string $itemName): void
54+
{
55+
$this->decoratedLogger->logFinish(...func_get_args());
56+
}
57+
58+
public function logItemProcessingFailed(string $item, Throwable $throwable): void
59+
{
60+
$this->decoratedLogger->logItemProcessingFailed(...func_get_args());
61+
}
62+
63+
public function logChildProcessStarted(int $index, int $pid, string $commandName): void
64+
{
65+
$this->decoratedLogger->logChildProcessStarted(...func_get_args());
66+
}
67+
68+
public function logChildProcessFinished(int $index): void
69+
{
70+
$this->decoratedLogger->logChildProcessFinished(...func_get_args());
71+
}
72+
73+
public function logUnexpectedChildProcessOutput(
74+
int $index,
75+
?int $pid,
76+
string $type,
77+
string $buffer,
78+
string $progressSymbol
79+
): void {
80+
$this->decoratedLogger->logUnexpectedChildProcessOutput(...func_get_args());
81+
}
82+
}

0 commit comments

Comments
 (0)