use \Psr\Log\LogLevel; use \Psr\Log\NullLogger; $logger = new NullLogger(); $logger->log(LogLevel::ERROR, 'An error occurred');
use \Monolog\Logger; use \Monolog\Handler\StreamHandler; $logger = new Logger('my_logger'); $logger->pushHandler(new StreamHandler('path/to/your.log', Logger::DEBUG)); $logger->info('This is an info message'); $logger->error('This is an error message');In this code, we create a new instance of the `Monolog\Logger` class, and add a `StreamHandler` instance to it using the `pushHandler` method. This handler will write log messages to a file located at `'path/to/your.log'`. We then log an info message and an error message using the `info` and `error` methods, respectively. The `Monolog` package library provides a more robust logging solution, with support for various log handlers and formatters.