phpstreamserver / logger
Logger plugin for PHPStreamServer
v0.3.0
2024-12-06 17:26 UTC
Requires
- php: >=8.2
- ext-pcntl: *
- ext-posix: *
- amphp/amp: ^3.0.2
- amphp/byte-stream: ^2.1.1
- amphp/socket: ^2.3.1
- phpstreamserver/core: ^0.3
- psr/log: ^3.0
- revolt/event-loop: ^1.0.6
README
Logger Plugin for PHPStreamServer
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.
Features
- 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.
Install
$ composer require phpstreamserver/core phpstreamserver/logger
Configure
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());
Run
$ php server.php start