super-kernel/logger 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

super-kernel/logger

Composer 安装命令:

composer require super-kernel/logger

包简介

The logger component for super-kernel.

README 文档

README

English | 中文文档

super-kernel/logger

Log component of SuperKernel framework

License PHP Monolog SuperKernel

Overview

super-kernel/logger is the official logging component of SuperKernel, providing two types of logging capabilities:

  • Standard Output Logging: By default, it outputs to the terminal (stdout) via the Logger class, suitable for development and CLI environments.

  • Monolog Extended Logging: Automatically creates developer-defined multichannel log instances via LoggerFactory, supporting various Handlers such as file, network, and queues.

This component conforms to the psr/log standard and is seamlessly integrated with SuperKernel's dependency injection system and configuration system.

Installation

composer require super-kernel/logger

Configuration

This component only scans properties with public visibility in classes annotated with #[Configuration(LoggerConfigInterface::class)].

Single handler configuration

<?php
declare(strict_types=1);

namespace Src\Config\Logger;

use Monolog\Formatter\LineFormatter;
use Monolog\Handler\StreamHandler;
use Monolog\Level;
use SuperKernel\Attribute\Configuration;
use SuperKernel\Logger\Contract\LoggerConfigInterface;

#[Configuration(LoggerConfigInterface::class)]
final class LoggerConfig implements LoggerConfigInterface
{ 
    public array $default = [ 
        'handler' => [ 
            'class' => StreamHandler::class, 
            'constructor' => [ 
                'stream' => 'logs/default.log', 
                'level' => Level::Debug, 
            ], 
        ], 
        'formatter' => [ 
            'class' => LineFormatter::class, 
            'constructor' => [ 
                'format' => null, 
                'dateFormat' => null, 
                'allowInlineLineBreaks' => true, 
            ], 
        ], 
    ];
}

Multiple handler configurations

<?php
declare(strict_types=1);

namespace Src\Config\Logger;

use Monolog\Formatter\LineFormatter;
use Monolog\Handler\StreamHandler;
use Monolog\Level;
use SuperKernel\Attribute\Configuration;
use SuperKernel\Logger\Contract\LoggerConfigInterface;

#[Configuration(LoggerConfigInterface::class)]
final class LoggerConfig implements LoggerConfigInterface
{ 
    public array $default = [ 
        [ 
            'handler' => [ 
                'class' => StreamHandler::class, 
                'constructor' => [ 
                        'stream' => 'logs/default.log', 
                        'level' => Level::Debug, 
                ], 
            ], 
            'formatter' => [ 
                'class' => LineFormatter::class, 
                'constructor' => [ 
                    'format' => null, 
                    'dateFormat' => null, 
                    'allowInlineLineBreaks' => true, 
                ], 
            ], 
        ], 
        [ 
            'handler' => [ 
                'class' => StreamHandler::class, 
                'constructor' => [ 
                    'stream' => 'logs/default.log', 
                    'level' => Level::Debug, 
                ], 
            ], 
            'formatter' => [ 
                'class' => LineFormatter::class, 
                'constructor' => [ 
                    'format' => null, 
                    'dateFormat' => null, 
                    'allowInlineLineBreaks' => true, 
                ], 
            ], 
        ], 
    ];
}

🚀 Example

Standard output log

<?php
declare(strict_types=1);

namespace Src\Service;

use Psr\Log\LoggerInterface;

final class DemoService
{ 
    public function __construct(private readonly LoggerInterface $logger) 
    { 
    }
    
    public function method() 
    { 
        $this->logger->info('Application started'); 
        $this->logger->error('Something went wrong'); 
    }
}

Standard output log

<?php
declare(strict_types=1);

namespace Src\Service;

use Psr\Log\LoggerInterface;

final class DemoService
{ 
    private readonly LoggerInterface $logger; 
    
    public function __construct(LoggerFactoryInterface $loggerFactory)
    {
        $this->logger = $loggerFactory->get('default');
    }
    
    public function method()
    {
        $this->logger->info('Application started');
        $this->logger->error('Something went wrong');
    }
}

Advanced

The logs output by framework components are standard output logs. We generally believe that such log output does not need to be recorded, but developers who have such needs can consider the following method:

nohup

nohup your_command > output.log 2>&1 &

After exiting the terminal, the process continues to run in the background, and standard output logs will be written to output.log.

setsid

setsid your_command > output.log 2>&1 &

Similar to nohup, but it does not inherit the original terminal's session ID, thus more completely detaching from the controlling terminal.

Override the LoggerInterface class provider

<?php
declare(strict_types=1);

namespace Src\Provider;

use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
use Stringable;
use SuperKernel\Attribute\Factory;
use SuperKernel\Attribute\Provider;
use Symfony\Component\Console\Output\ConsoleOutput;

#[ 
    Provider(class: LoggerInterface::class, priority: 2), 
    Factory,
]
final class Logger implements LoggerInterface
{ 
    public function __invoke(LoggerFactoryInterface $loggerFactory): LoggerInterface 
    { 
        return $loggerFactory->get('your logger name'); 
    }
}

More usage

Please visit Visit monolog/monolog to learn more.

super-kernel/logger 适用场景与选型建议

super-kernel/logger 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 39 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 10 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「logger」 「swoole」 「super-kernel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 super-kernel/logger 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 super-kernel/logger 我们能提供哪些服务?
定制开发 / 二次开发

基于 super-kernel/logger 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 39
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 6
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-10-10