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 44
55namespace App \Monolog \Processor ;
66
7+ use App \Entity \UserSerializableInterface ;
78use Monolog \Processor \ProcessorInterface ;
89use Symfony \Component \Serializer \Normalizer \NormalizerInterface ;
910
@@ -23,11 +24,25 @@ public function __invoke(array $record): array
2324 }
2425
2526 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 ' )) {
2732 try {
2833 $ record ['context ' ][$ key ] = $ this ->normalizer ->normalize ($ value , 'json ' , [
2934 '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 ;
3146 },
3247 ]);
3348 } catch (\Throwable $ e ) {
You can’t perform that action at this time.
0 commit comments