PHP code example of flytachi / winter-logger

1. Go to this page and download the library: Download flytachi/winter-logger 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/ */

    

flytachi / winter-logger example snippets


use Flytachi\Winter\Logger\{LoggerFactory, LoggerManager};
use Flytachi\Winter\Logger\Context\ProcessContext;
use Monolog\Level;

LoggerFactory::setManager(new LoggerManager(
    contextStorage: new ProcessContext(),      // CoroutineContext under Swoole
    channels: [
        'http' => ['level' => Level::Info,  'format' => 'line', 'output' => 'stderr'],
        'cli'  => ['level' => Level::Debug, 'format' => 'line', 'output' => 'stdout', 'color' => true],
    ],
));

LoggerFactory::setDefaultChannel('http');

use Flytachi\Winter\Logger\{Log, LoggerFactory};

Log::info('user created', ['id' => 42]);                             // default channel
LoggerFactory::getLogger(UserService::class)->info('cache warmed');  // named after the class
LoggerFactory::channel('cli')->warning('rate limit hit');            // a specific channel

$storage = LoggerFactory::contextStorage();

$storage->set('request_id', $requestId);
$storage->set('user_id', $userId);

// ... anywhere downstream
Log::info('processing');   // carries request_id and user_id

$storage->clear();         // at the end — mandatory in a long-running process

[2026-01-01 12:00:00] [INFO ] -http- [4821]: user created {"id":42}
[2026-01-01 12:00:00] [INFO ] -http- [4821] (UserService): cache warmed {"class":"UserService"}
[2026-01-01 12:00:00] [WARN ] -cli-  [4821]: rate limit hit