use Psr\Log\LoggerInterface; use Psr\Log\LogLevel; class MyClass { private $logger; public function __construct(LoggerInterface $logger) { $this->logger = $logger; } public function doSomething() { // something goes wrong $this->logger->log(LogLevel::CRITICAL, 'An error occurred!'); } }In this example, a MyClass is defined that receives a LoggerInterface instance as a constructor parameter. The doSomething method of MyClass calls the critical method of the logger when an error occurs. One package library that implements the PSR-3 LoggerInterface is Monolog, a popular logging library for PHP.