Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Chg #130, #133: Changed `Message::parse()` to conform to PSR-3 (@technicated, @vjik)
- Enh #135: Add validation for `$traceLevel` in `SystemContextProvider` to ensure values are greater than or equal to zero (@rekmixa)
- Enh #137: Explicitly import classes, functions, and constants in "use" section (@mspirkov)
- Enh #138: Moved the final log flush from `register_shutdown_function()` to the `Logger::__destruct()` method (@olegbaturin)

## 2.2.0 December 13, 2025

Expand Down
12 changes: 4 additions & 8 deletions src/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use function in_array;
use function is_string;
use function microtime;
use function register_shutdown_function;
use function sprintf;

/**
Expand Down Expand Up @@ -87,14 +86,11 @@
) {
$this->setTargets($targets);
$this->contextProvider = $contextProvider ?? new SystemContextProvider();
}

register_shutdown_function(function () {
// make regular flush before other shutdown functions, which allows session data collection and so on
$this->flush();
// make sure log entries written by shutdown functions are also flushed
// ensure "flush()" is called last when there are multiple shutdown functions
register_shutdown_function([$this, 'flush'], true);
});
public function __destruct()
{
$this->flush(true);
}

/**
Expand Down Expand Up @@ -134,7 +130,7 @@
array_merge($this->contextProvider->getContext(), $context),
);

if ($this->flushInterval > 0 && count($this->messages) >= $this->flushInterval) {

Check warning on line 133 in src/Logger.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "GreaterThan": @@ @@ array_merge($this->contextProvider->getContext(), $context), ); - if ($this->flushInterval > 0 && count($this->messages) >= $this->flushInterval) { + if ($this->flushInterval >= 0 && count($this->messages) >= $this->flushInterval) { $this->flush(); } }
$this->flush();
}
}
Expand Down Expand Up @@ -231,7 +227,7 @@
*
* @psalm-assert string $level
*/
public static function assertLevelIsString(mixed $level): void

Check warning on line 230 in src/Logger.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "PublicVisibility": @@ @@ * * @psalm-assert string $level */ - public static function assertLevelIsString(mixed $level): void + protected static function assertLevelIsString(mixed $level): void { if (is_string($level)) { return;
{
if (is_string($level)) {
return;
Expand Down
10 changes: 5 additions & 5 deletions tests/LoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,11 @@ public function testDispatchWithSuccessTargetCollect(): void
->getMockForAbstractClass();

$target
->expects($this->once())
->expects($this->exactly(2))
->method('collect')
->with(
$this->equalTo([$message]),
$this->equalTo(true),
->withConsecutive(
[$this->equalTo([$message]), $this->equalTo(true)],
[$this->equalTo([]), $this->equalTo(true)],
);

$logger = new Logger(['fakeTarget' => $target]);
Expand Down Expand Up @@ -383,7 +383,7 @@ public function testDispatchWithFakeTarget2ThrowExceptionWhenCollect(): void
->getMockForAbstractClass();

$target1
->expects($this->exactly(2))
->expects($this->exactly(3))
->method('collect')
->withConsecutive(
[$this->equalTo([$message]), $this->equalTo(true)],
Expand Down
Loading