It contains a stack of Handlers and a stack of Processors,
and uses them to store records that are added to it.
use Monolog\Logger; use Monolog\Handler\StreamHandler; $log = new Logger('app_logger'); $log->pushHandler(new StreamHandler('app.log', Logger::DEBUG)); $log->info('New data received'); $log->error('Error occurred while processing data');
use Monolog\Logger; use Monolog\Handler\StreamHandler; use Monolog\Handler\SwiftMailerHandler; $log = new Logger('app_logger'); $log->pushHandler(new StreamHandler('app.log', Logger::DEBUG)); $log->pushHandler(new SwiftMailerHandler($mailer, Logger::ERROR)); $log->info('New data received'); $log->error('Error occurred while processing data');In this example, we create a logger instance called 'app_logger' and add two handlers. The first handler logs messages to a file called 'app.log', and the second handler sends an email when there's an error. We then use the logger to log an info message and an error message. Overall, PHP Monolog Logger is a powerful and flexible logging library that is widely used in PHP applications. It is easy to use and comes with many useful features for log management.