Skip to content

Commit bc5564d

Browse files
authored
Improve Logger docs and re-order the methods (#169)
1 parent b3bfa6a commit bc5564d

File tree

5 files changed

+46
-24
lines changed

5 files changed

+46
-24
lines changed

src/Logger/Logger.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@
1919
interface Logger
2020
{
2121
/**
22+
* Logs the configuration before the start of the processing.
23+
*
2224
* @param positive-int $batchSize
2325
* @param 0|positive-int|null $numberOfItems
26+
* @param string $itemName Name of the item; Already in the singular or plural
27+
* form.
2428
*/
2529
public function logConfiguration(
2630
Configuration $configuration,
@@ -35,15 +39,33 @@ public function logConfiguration(
3539
*/
3640
public function startProgress(?int $numberOfItems): void;
3741

42+
/**
43+
* @param positive-int|0 $steps
44+
*/
3845
public function advance(int $steps = 1): void;
3946

47+
/**
48+
* @param string $itemName Name of the item; Already in the singular or plural form.
49+
*/
4050
public function finish(string $itemName): void;
4151

42-
public function logUnexpectedOutput(string $buffer, string $progressSymbol): void;
52+
public function logItemProcessingFailed(string $item, Throwable $throwable): void;
4353

54+
/**
55+
* @param string $commandName Executed command for the child process.To not confuse
56+
* with the Symfony command name which is just an element of
57+
* the command.
58+
*/
4459
public function logCommandStarted(string $commandName): void;
4560

4661
public function logCommandFinished(): void;
4762

48-
public function logItemProcessingFailed(string $item, Throwable $throwable): void;
63+
/**
64+
* Logs the "unexpected" child output. By unexpected is meant that the main
65+
* process expects the child to output the progress symbol to communicate its
66+
* progression. Any other sort of output is considered "unexpected".
67+
*
68+
* @param string $buffer Child process output.
69+
*/
70+
public function logUnexpectedOutput(string $buffer, string $progressSymbol): void;
4971
}

src/Logger/NullLogger.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function finish(string $itemName): void
4343
// Do nothing.
4444
}
4545

46-
public function logUnexpectedOutput(string $buffer, string $progressSymbol): void
46+
public function logItemProcessingFailed(string $item, Throwable $throwable): void
4747
{
4848
// Do nothing.
4949
}
@@ -58,7 +58,7 @@ public function logCommandFinished(): void
5858
// Do nothing.
5959
}
6060

61-
public function logItemProcessingFailed(string $item, Throwable $throwable): void
61+
public function logUnexpectedOutput(string $buffer, string $progressSymbol): void
6262
{
6363
// Do nothing.
6464
}

src/Logger/StandardLogger.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -128,20 +128,14 @@ public function finish(string $itemName): void
128128
unset($this->progressBar);
129129
}
130130

131-
public function logUnexpectedOutput(string $buffer, string $progressSymbol): void
131+
public function logItemProcessingFailed(string $item, Throwable $throwable): void
132132
{
133-
$this->output->writeln('');
134133
$this->output->writeln(sprintf(
135-
'<comment>%s</comment>',
136-
str_pad(
137-
' Process Output ',
138-
$this->terminalWidth,
139-
'=',
140-
STR_PAD_BOTH,
141-
),
134+
"Failed to process \"%s\": %s\n%s",
135+
$item,
136+
$throwable->getMessage(),
137+
$throwable->getTraceAsString(),
142138
));
143-
$this->output->writeln(str_replace($progressSymbol, '', $buffer));
144-
$this->output->writeln('');
145139
}
146140

147141
public function logCommandStarted(string $commandName): void
@@ -154,13 +148,19 @@ public function logCommandFinished(): void
154148
$this->logger->debug('Command finished');
155149
}
156150

157-
public function logItemProcessingFailed(string $item, Throwable $throwable): void
151+
public function logUnexpectedOutput(string $buffer, string $progressSymbol): void
158152
{
153+
$this->output->writeln('');
159154
$this->output->writeln(sprintf(
160-
"Failed to process \"%s\": %s\n%s",
161-
$item,
162-
$throwable->getMessage(),
163-
$throwable->getTraceAsString(),
155+
'<comment>%s</comment>',
156+
str_pad(
157+
' Process Output ',
158+
$this->terminalWidth,
159+
'=',
160+
STR_PAD_BOTH,
161+
),
164162
));
163+
$this->output->writeln(str_replace($progressSymbol, '', $buffer));
164+
$this->output->writeln('');
165165
}
166166
}

tests/Logger/DummyLogger.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function finish(string $itemName): void
5858
];
5959
}
6060

61-
public function logUnexpectedOutput(string $buffer, string $progressSymbol): void
61+
public function logItemProcessingFailed(string $item, Throwable $throwable): void
6262
{
6363
$this->records[] = [
6464
__FUNCTION__,
@@ -82,7 +82,7 @@ public function logCommandFinished(): void
8282
];
8383
}
8484

85-
public function logItemProcessingFailed(string $item, Throwable $throwable): void
85+
public function logUnexpectedOutput(string $buffer, string $progressSymbol): void
8686
{
8787
$this->records[] = [
8888
__FUNCTION__,

tests/Logger/FakeLogger.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function finish(string $itemName): void
4444
throw new DomainException('Unexpected call.');
4545
}
4646

47-
public function logUnexpectedOutput(string $buffer, string $progressSymbol): void
47+
public function logItemProcessingFailed(string $item, Throwable $throwable): void
4848
{
4949
throw new DomainException('Unexpected call.');
5050
}
@@ -59,7 +59,7 @@ public function logCommandFinished(): void
5959
throw new DomainException('Unexpected call.');
6060
}
6161

62-
public function logItemProcessingFailed(string $item, Throwable $throwable): void
62+
public function logUnexpectedOutput(string $buffer, string $progressSymbol): void
6363
{
6464
throw new DomainException('Unexpected call.');
6565
}

0 commit comments

Comments
 (0)