{"action":"closed","issue":{"url":"https://api.github.com/repos/Seldaek/monolog/issues/560","repository_url":"https://api.github.com/repos/Seldaek/monolog","labels_url":"https://api.github.com/repos/Seldaek/monolog/issues/560/labels{/name}","comments_url":"https://api.github.com/repos/Seldaek/monolog/issues/560/comments","events_url":"https://api.github.com/repos/Seldaek/monolog/issues/560/events","html_url":"https://github.com/Seldaek/monolog/issues/560","id":73632897,"number":560,"title":"Support for JsonSerializable","user":{"login":"UlrichEckhardt","id":8566055,"avatar_url":"https://avatars.githubusercontent.com/u/8566055?v=3","gravatar_id":"","url":"https://api.github.com/users/UlrichEckhardt","html_url":"https://github.com/UlrichEckhardt","followers_url":"https://api.github.com/users/UlrichEckhardt/followers","following_url":"https://api.github.com/users/UlrichEckhardt/following{/other_user}","gists_url":"https://api.github.com/users/UlrichEckhardt/gists{/gist_id}","starred_url":"https://api.github.com/users/UlrichEckhardt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/UlrichEckhardt/subscriptions","organizations_url":"https://api.github.com/users/UlrichEckhardt/orgs","repos_url":"https://api.github.com/users/UlrichEckhardt/repos","events_url":"https://api.github.com/users/UlrichEckhardt/events{/privacy}","received_events_url":"https://api.github.com/users/UlrichEckhardt/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/Seldaek/monolog/milestones/1","html_url":"https://github.com/Seldaek/monolog/milestones/2.0","labels_url":"https://api.github.com/repos/Seldaek/monolog/milestones/1/labels","id":338543,"number":1,"title":"2.0","description":"BC breaks for 2.0","creator":{"login":"Seldaek","id":183678,"avatar_url":"https://avatars.githubusercontent.com/u/183678?v=3","gravatar_id":"","url":"https://api.github.com/users/Seldaek","html_url":"https://github.com/Seldaek","followers_url":"https://api.github.com/users/Seldaek/followers","following_url":"https://api.github.com/users/Seldaek/following{/other_user}","gists_url":"https://api.github.com/users/Seldaek/gists{/gist_id}","starred_url":"https://api.github.com/users/Seldaek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Seldaek/subscriptions","organizations_url":"https://api.github.com/users/Seldaek/orgs","repos_url":"https://api.github.com/users/Seldaek/repos","events_url":"https://api.github.com/users/Seldaek/events{/privacy}","received_events_url":"https://api.github.com/users/Seldaek/received_events","type":"User","site_admin":false},"open_issues":5,"closed_issues":17,"state":"open","created_at":"2013-05-21T17:53:00Z","updated_at":"2016-05-26T18:21:50Z","due_on":null,"closed_at":null},"comments":3,"created_at":"2015-05-06T14:09:17Z","updated_at":"2016-05-26T18:21:50Z","closed_at":"2016-05-26T18:21:50Z","body":"I'd like to see support for objects that implement the JsonSerializable interface. At the moment, I have code like this:\r\n```\r\nclass Example implements \\JsonSerializable\r\n{\r\n    public function jsonSerialize()\r\n    {\r\n        return array('data' => 'structure');\r\n    }\r\n}\r\n\r\n$logger->info('mapped', array('bar' => new Example));\r\n$logger->info('array', array(new Example));\r\n```\r\nThe resulting output is this:\r\n```\r\n[2015-05-06 15:54:30] log.INFO: mapped {\"bar\":\"[object] (Example: {\\\"data\\\":\\\"structure\\\"})\"} []\r\n[2015-05-06 15:54:32] log.INFO: array [\"[object] (Example: {\\\"data\\\":\\\"structure\\\"})\"] []\r\n```\r\nThis isn't really readable due to the backslash-escaped double quotes. With a small change, you can get this output though:\r\n```\r\n[2015-05-06 15:56:05] log.INFO: mapped {\"bar\":{\"data\":\"structure\"}} []\r\n[2015-05-06 15:56:05] log.INFO: array [{\"data\":\"structure\"}] []\r\n```\r\nAll that you need to do is to check for the JsonSerializable interface in the normalize() function of class NormalizerFormatter (code based on 1.13.1):\r\n```\r\n    ....\r\n    if (is_object($data)) {\r\n        if ($data instanceof Exception) {\r\n            return $this->normalizeException($data);\r\n        }\r\n        if ($data instanceof \\JsonSerializable) {\r\n            return $this->normalize($data->jsonSerialize());\r\n        }\r\n        return sprintf(\"[object] (%s: %s)\", get_class($data), $this->toJson($data, true));\r\n    }\r\n    ...\r\n```\r\n\r\nI haven't tested this thoroughly, so please don't just apply that change. I just wanted to ask whether that was a worthwhile approach at all or for any other remarks.\r\n\r\n\r\n"}}
{"actor":{"display_login":"Seldaek"}}