Skip to content

Commit

Permalink
Merge branch '2.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Feb 6, 2023
2 parents 852643b + f259e2b commit 9b5daea
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 3.3.1 (2023-02-06)

* Fixed Logger not being serializable anymore (#1792)

### 3.3.0 (2023-02-06)

* Deprecated FlowdockHandler & Formatter as the flowdock service was shutdown (#1748)
Expand Down Expand Up @@ -80,6 +84,10 @@ New deprecations:
value equal to what `Logger::WARNING` was giving you.
- `Logger::getLevelName()` is now deprecated.

### 2.9.1 (2023-02-06)

* Fixed Logger not being serializable anymore (#1792)

### 2.9.0 (2023-02-05)

* Deprecated FlowdockHandler & Formatter as the flowdock service was shutdown (#1748)
Expand Down
5 changes: 5 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ parameters:
count: 1
path: src/Monolog/Logger.php

-
message: "#^Variable property access on \\$this\\(Monolog\\\\Logger\\)\\.$#"
count: 1
path: src/Monolog/Logger.php

-
message: "#^Comparison operation \"\\<\" between int\\<1, 32\\> and 1 is always false\\.$#"
count: 1
Expand Down
31 changes: 31 additions & 0 deletions src/Monolog/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -701,4 +701,35 @@ protected function handleException(Throwable $e, LogRecord $record): void

($this->exceptionHandler)($e, $record);
}

/**
* @return array<string, mixed>
*/
public function __serialize(): array
{
return [
'name' => $this->name,
'handlers' => $this->handlers,
'processors' => $this->processors,
'microsecondTimestamps' => $this->microsecondTimestamps,
'timezone' => $this->timezone,
'exceptionHandler' => $this->exceptionHandler,
'logDepth' => $this->logDepth,
'detectCycles' => $this->detectCycles,
];
}

/**
* @param array<string, mixed> $data
*/
public function __unserialize(array $data): void
{
foreach (['name', 'handlers', 'processors', 'microsecondTimestamps', 'timezone', 'exceptionHandler', 'logDepth', 'detectCycles'] as $property) {
if (isset($data[$property])) {
$this->$property = $data[$property];
}
}

$this->fiberLogDepth = new \WeakMap();
}
}
10 changes: 10 additions & 0 deletions tests/Monolog/LoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,16 @@ public function testCustomHandleException()
$logger->info('test');
}

public function testSerializable()
{
$logger = new Logger(__METHOD__);
$copy = unserialize(serialize($logger));
self::assertInstanceOf(Logger::class, $copy);
self::assertSame($logger->getName(), $copy->getName());
self::assertSame($logger->getTimezone()->getName(), $copy->getTimezone()->getName());
self::assertSame($logger->getHandlers(), $copy->getHandlers());
}

public function testReset()
{
$logger = new Logger('app');
Expand Down

0 comments on commit 9b5daea

Please sign in to comment.