1. Go to this page and download the library: Download iapotheca/log-processor library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
namespace App\Logging;
use Iapotheca\LogProcessor\Processor;
use Monolog\Logger;
use PhpAmqpLib\Connection\AMQPSocketConnection;
use PhpAmqpLib\Channel\AMQPChannel;
use Monolog\Handler\AmqpHandler;
class RabbitmqLogger
{
public function __invoke(array $config)
{
$connection = new AMQPSocketConnection(
$config['host'],
$config['port'],
$config['user'],
$config['password']
);
$channel = new AMQPChannel($connection);
$logger = new Logger($config['log-name']);
$handler = new AmqpHandler($channel, $config['exchange-name']);
$handler->pushProcessor(new Processor(config('app.name'), [
// these are the observed keys within the log message
'KEY_ONE', 'KEY_TWO'
]));
$logger->pushHandler($handler);
return $logger;
}
}