Skip to content

Commit 9b5daea

Browse files
committed
Merge branch '2.x'
2 parents 852643b + f259e2b commit 9b5daea

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### 3.3.1 (2023-02-06)
2+
3+
* Fixed Logger not being serializable anymore (#1792)
4+
15
### 3.3.0 (2023-02-06)
26

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

87+
### 2.9.1 (2023-02-06)
88+
89+
* Fixed Logger not being serializable anymore (#1792)
90+
8391
### 2.9.0 (2023-02-05)
8492

8593
* Deprecated FlowdockHandler & Formatter as the flowdock service was shutdown (#1748)

phpstan-baseline.neon

+5
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ parameters:
9090
count: 1
9191
path: src/Monolog/Logger.php
9292

93+
-
94+
message: "#^Variable property access on \\$this\\(Monolog\\\\Logger\\)\\.$#"
95+
count: 1
96+
path: src/Monolog/Logger.php
97+
9398
-
9499
message: "#^Comparison operation \"\\<\" between int\\<1, 32\\> and 1 is always false\\.$#"
95100
count: 1

src/Monolog/Logger.php

+31
Original file line numberDiff line numberDiff line change
@@ -701,4 +701,35 @@ protected function handleException(Throwable $e, LogRecord $record): void
701701

702702
($this->exceptionHandler)($e, $record);
703703
}
704+
705+
/**
706+
* @return array<string, mixed>
707+
*/
708+
public function __serialize(): array
709+
{
710+
return [
711+
'name' => $this->name,
712+
'handlers' => $this->handlers,
713+
'processors' => $this->processors,
714+
'microsecondTimestamps' => $this->microsecondTimestamps,
715+
'timezone' => $this->timezone,
716+
'exceptionHandler' => $this->exceptionHandler,
717+
'logDepth' => $this->logDepth,
718+
'detectCycles' => $this->detectCycles,
719+
];
720+
}
721+
722+
/**
723+
* @param array<string, mixed> $data
724+
*/
725+
public function __unserialize(array $data): void
726+
{
727+
foreach (['name', 'handlers', 'processors', 'microsecondTimestamps', 'timezone', 'exceptionHandler', 'logDepth', 'detectCycles'] as $property) {
728+
if (isset($data[$property])) {
729+
$this->$property = $data[$property];
730+
}
731+
}
732+
733+
$this->fiberLogDepth = new \WeakMap();
734+
}
704735
}

tests/Monolog/LoggerTest.php

+10
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,16 @@ public function testCustomHandleException()
699699
$logger->info('test');
700700
}
701701

702+
public function testSerializable()
703+
{
704+
$logger = new Logger(__METHOD__);
705+
$copy = unserialize(serialize($logger));
706+
self::assertInstanceOf(Logger::class, $copy);
707+
self::assertSame($logger->getName(), $copy->getName());
708+
self::assertSame($logger->getTimezone()->getName(), $copy->getTimezone()->getName());
709+
self::assertSame($logger->getHandlers(), $copy->getHandlers());
710+
}
711+
702712
public function testReset()
703713
{
704714
$logger = new Logger('app');

0 commit comments

Comments
 (0)