use Monolog\Logger; use Monolog\Handler\StreamHandler; // create a log channel $log = new Logger('debug_logger'); $log->pushHandler(new StreamHandler('debug.log', Logger::DEBUG)); // add records to the log $log->debug('Debug message'); $log->info('Info message'); $log->warning('Warning message'); $log->error('Error message');
use Monolog\Logger; use Monolog\Handler\StreamHandler; // create a log channel $log = new Logger('debug_logger'); $log->pushHandler(new StreamHandler('php://stdout', Logger::DEBUG)); // add records to the log $log->debug('Debug message'); $log->info('Info message'); $log->warning('Warning message'); $log->error('Error message');In this example, we create a logger named `debug_logger` and add a StreamHandler to log messages to standard output (`php://stdout`). We then add four log records of increasing severity, from `debug` to `error`. The Monolog library can be installed via Composer and the package name is `monolog/monolog`. Overall, the `debug` logger in Monolog is a useful tool for developrs to diagnose and troubleshoot issues in their PHP applications.