File tree Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change 4
4
5
5
namespace App \Monolog \Processor ;
6
6
7
+ use App \Entity \UserSerializableInterface ;
7
8
use Monolog \Processor \ProcessorInterface ;
8
9
use Symfony \Component \Serializer \Normalizer \NormalizerInterface ;
9
10
@@ -23,11 +24,25 @@ public function __invoke(array $record): array
23
24
}
24
25
25
26
foreach ($ record ['context ' ] as $ key => $ value ) {
26
- if ($ this ->normalizer ->supportsNormalization ($ value , 'json ' )) {
27
+ if (\is_object ($ value ) && method_exists ($ value , '__toString ' )) {
28
+ $ record ['context ' ][$ key ] = $ value ->__toString ();
29
+ } elseif ($ value instanceof UserSerializableInterface) {
30
+ $ record ['context ' ][$ key ] = json_encode ($ value ->userSerialize ()); // TODO use a custom normalizer
31
+ } elseif ($ this ->normalizer ->supportsNormalization ($ value , 'json ' )) {
27
32
try {
28
33
$ record ['context ' ][$ key ] = $ this ->normalizer ->normalize ($ value , 'json ' , [
29
34
'circular_reference_handler ' => static function ($ object ) {
30
- return (string ) $ object ;
35
+ if (!\is_object ($ object )) {
36
+ return null ;
37
+ }
38
+ if (method_exists ($ object , '__toString ' )) {
39
+ return $ object ->__toString ();
40
+ }
41
+ if (!empty ($ object ->id )) {
42
+ return (string ) $ object ->id ;
43
+ }
44
+
45
+ return null ;
31
46
},
32
47
]);
33
48
} catch (\Throwable $ e ) {
You can’t perform that action at this time.
0 commit comments