use Monolog\Logger; use Monolog\Handler\StreamHandler; // create a log channel $log = new Logger('name'); $log->pushHandler(new StreamHandler('path/to/your.log', Logger::WARNING)); // add records to the log $log->warning('This is a warning message'); $log->error('This is an error message');
use Monolog\Logger; use Monolog\Handler\RotatingFileHandler; use Monolog\Handler\AmqpHandler; use PhpAmqpLib\Connection\AMQPStreamConnection; // create a log channel $log = new Logger('name'); $log->pushHandler(new RotatingFileHandler('path/to/your.log', 30, Logger::WARNING)); // set up AMQP connection $connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest'); $channel = $connection->channel(); // create AMQP handler $handler = new AmqpHandler($channel, 'exchange-name', 'routing-key'); $log->pushHandler($handler); // add records to the log $log->warning('This is a warning message'); $log->error('This is an error message'); $channel->close(); $connection->close();This code uses a RotatingFileHandler to write log messages to a file, and an AmqpHandler to send log messages to a RabbitMQ exchange using the PhpAmqpLib package. This requires setting up a RabbitMQ server and creating an exchange and queue to receive log messages. Overall, Monolog offers a wide range of logging handlers and formatters, making it a versatile choice for PHP logging.