Home

Awesome

<p align="center"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/phpstreamserver/.github/refs/heads/main/assets/phpss_logger_light.svg"> <img alt="PHPStreamServer logo" align="center" width="70%" src="https://raw.githubusercontent.com/phpstreamserver/.github/refs/heads/main/assets/phpss_logger_dark.svg"> </picture> </p>

Logger Plugin for PHPStreamServer

PHP >=8.2 Version Downloads

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

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