PHPackages                             kriss/webman-logger - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. kriss/webman-logger

Abandoned → [webman-tech/logger](/?search=webman-tech%2Flogger)Library[Logging &amp; Monitoring](/categories/logging)

kriss/webman-logger
===================

webman logger plugin

v5.0.19(2mo ago)889MITPHPPHP ^8.2

Since May 30Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/webman-tech/logger)[ Packagist](https://packagist.org/packages/kriss/webman-logger)[ RSS](/packages/kriss-webman-logger/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (8)Dependencies (6)Versions (59)Used By (0)

webman-tech/logger
==================

[](#webman-techlogger)

本项目是从 [webman-tech/components-monorepo](https://github.com/orgs/webman-tech/components-monorepo) 自动 split 出来的，请勿直接修改

简介
--

[](#简介)

webman 日志统筹化管理插件，基于 Monolog 实现，旨在解决 webman 原生日志配置的一些不便之处：

1. 当日志量较大时，不可能所有日志都通过 `Log::info` 的形式记录，需要分 channel 管理
2. 当 channel 数量较多时，每个都需要单独定义，基本上是复制粘贴操作，后期如果需要切换所有通道的写入方式，需要逐一修改，维护困难
3. 每次通过 `Log::channel('channelName')` 的形式调用时，由于 `channelName` 是字符串，容易拼写错误导致日志记录失败
4. 没有充分利用 Monolog 的 formatter 和 processor 功能

本插件正是为了解决以上问题，针对多 `channel` 模式进行统筹优化管理。

功能特性
----

[](#功能特性)

- **多通道管理**：统一管理多个日志通道，避免重复配置
- **模式化处理**：支持多种日志处理模式（Split、Mix、Stdout、Redis等）
- **格式化支持**：提供结构化的日志格式化器
- **处理器机制**：支持多种日志处理器，丰富日志内容
- **类型安全**：通过继承 Logger 类提供方法提示，避免拼写错误
- **灵活配置**：支持全局和通道级别的灵活配置
- **性能优化**：使用 WeakMap 管理 Logger 实例，支持资源释放

安装
--

[](#安装)

```
composer require webman-tech/logger
```

快速开始
----

[](#快速开始)

### 基本配置

[](#基本配置)

1. 在 `config/plugin/webman-tech/logger/log-channel.php` 中配置日志通道：

```
return [
    'channels' => [
        'app',
        'sql',
        'business',
    ],
];
```

2. 在 `config/log.php` 中合并配置：

```
use support\facade\Logger;

return array_merge(
    [
        // 原有配置
    ],
    Logger::getLogChannelConfigs()
);
```

3. 创建自定义 Logger 类（可选但推荐）：

```
