Skip to content

[READ ONLY] Logger Plugin for PHPStreamServer

Notifications You must be signed in to change notification settings

phpstreamserver/logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHPStreamServer logo

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

  • 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

About

[READ ONLY] Logger Plugin for PHPStreamServer

Topics

Resources

Stars

Watchers

Forks

Languages