Proper logging in PHP with PSR-3 0 ▲ ocramius.github.io 2 hours ago · 7 min read1478 words · Tech · hide · 0 comments Who is this article for? This post is for people that do day-by-day busywork coding, and for team leads that want to direct their peers towards better logging practices. Note that this article comes from my regular need to present these exact points to different people, multiple times a year, in multiple teams, in multiple companies. Also, we will not talk about how to configure a PSR-3 logger, but rather how to use one. Handling errors properly Error/exception handling is the main use-case for logging. When logging exceptions, please pass the Throwable instance to the 'exception' context key. try { // logic here } catch (SomeException $failed) { $this->logger->error('Something went wrong', [ 'exception' => $failed, ]); } Avoid cluttering the logger call with data deriving from the exception: it's not the logger call-site's job, and you are just repeating work. I often see unnecessary code like: try { // logic here } catch (SomeException $failed) { $this->logger->error('Something went… No comments yet. Log in to reply on the Fediverse. Comments will appear here.