// Create a log instance $log = new \Psr\Log\LoggerInterface(); // Log an error message $log->error('An error occurred.'); // Log an exception try { // Some code that might throw an exception } catch (\Exception $e) { $log->error('Caught exception: ' . $e->getMessage()); }
// Create a log instance $log = new \Psr\Log\LoggerInterface(); // Add a custom log writer $log->addWriter(new \MyCustomLogWriter()); // Log a message $log->info('User logged in.'); // Example custom log writer class class MyCustomLogWriter implements \Psr\Log\LoggerInterface { public function log($level, $message, array $context = array()) { // Implement custom logging logic here } }In the first example, we create a new log instance and log an error message and a caught exception. In the second example, we add a custom log writer to the log instance and log an info message using the `info()` method. The custom log writer class implements the `log()` method to define custom logging logic. The PHP Log model is part of the PHP Core package library, which is provided by default with PHP. However, there are also third-party packages that provide additional features and functionality for managing logs, such as Monolog or Symfony's Logging Component.