The Logger Plugin for PHPStreamServer extends the core functionality by providing a configurable PSR-compatible logger. It allows to capture and route logs from different channels and severities to various destinations, such as files, stdout, Graylog servers (via the GELF protocol), and syslog.
- Route logs by channel and severity to different destinations.
- Rotate file logs.
- Compress file logs.
- Customizable format: Supports JSON, human-readable and custom formats.
- Customizable handlers: Implement your own custom log handlers.
$ composer require phpstreamserver/core phpstreamserver/logger
Here is an example of a simple server configuration with logger.
// server.php
use PHPStreamServer\Core\Plugin\Supervisor\WorkerProcess;
use PHPStreamServer\Core\Server;
use PHPStreamServer\Plugin\Logger\Handler\ConsoleHandler;
use PHPStreamServer\Plugin\Logger\Handler\FileHandler;
use PHPStreamServer\Plugin\Logger\LoggerInterface;
use PHPStreamServer\Plugin\Logger\LoggerPlugin;
$server = new Server();
$server->addPlugin(
new LoggerPlugin(
new ConsoleHandler(),
new FileHandler(
filename: __DIR__ . '/log.log',
rotate: true,
),
),
);
$server->addWorker(
new WorkerProcess(
name: 'Supervised Program',
count: 1,
onStart: function (WorkerProcess $worker): void {
$logger = $worker->container->getService(LoggerInterface::class);
$logger->info('test message');
},
),
);
exit($server->run());
$ php server.php start