PHPackages                             topphp/topphp-log - 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. topphp/topphp-log

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

topphp/topphp-log
=================

日志工具组件

v1.0.3(6y ago)1814MITPHPPHP ~7.2

Since Mar 6Pushed 5y ago1 watchersCompare

[ Source](https://github.com/topphp/topphp-log)[ Packagist](https://packagist.org/packages/topphp/topphp-log)[ RSS](/packages/topphp-topphp-log/feed)WikiDiscussions master Synced today

READMEChangelog (4)Dependencies (4)Versions (5)Used By (4)

topphp-log
==========

[](#topphp-log)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ae0f52c74a61961e9db29f01772b38ba685e4a7834a3d52453f28b289d9029e3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f707068702f636f6d706f6e656e742d6275696c6465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/topphp/component-builder)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/005f716166c16d1e3c68f324454da4b8e9beb429be5097bd10b75455fb02117d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746f707068702f636f6d706f6e656e742d6275696c6465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/topphp/component-builder)

> 这是一个日志管理工具，包含文件存储File、阿里云日志存储Aliyun、Socket日志

包含方法
----

[](#包含方法)

- 返回TP日志原始句柄 handler 方法
- 获取日志组件类内部错误信息 getErrorMsg 方法
- 快速生成格式化日志数据 generateData 方法
- 非实时记录日志 record 方法
- 实时记录日志 write 方法（推荐）
- 八大日志级别快捷方法（debug, info, notice, warning, error, critical, alert, emergency）
- SQl类型日志 sql 方法
- 清空内存中的日志信息 clear 方法等

组件结构
----

[](#组件结构)

```
config/
src/
tests/
vendor/

```

安装
--

[](#安装)

```
    composer require topphp/topphp-log
```

日志配置
----

[](#日志配置)

```
    return [
        // 默认日志记录通道
        'default'      => env('log.channel', 'file'),
        // 日志记录级别
        'level'        => [],
        // 日志类型记录的通道 ['error'=>'email',...]
        'type_channel' => [],
        // 关闭全局日志写入
        'close'        => false,
        // 全局日志处理 支持闭包
        'processor'    => null,

        // 日志通道列表
        'channels'     => [
            'file'   => [
                // 日志记录方式
                'type'           => 'File',
                // 日志保存目录（不传默认写入runtime/log内）
                'path'           => '',
                // 单文件日志写入
                'single'         => false,
                // 独立日志级别
                'apart_level'    => [],
                // 最大日志文件数量
                'max_files'      => 0,
                // 使用JSON格式记录
                'json'           => false,
                // 日志处理
                'processor'      => null,
                // 关闭通道日志写入
                'close'          => false,
                // 时间记录格式
                'time_format'    => 'c',
                // 日志输出格式化
                'format'         => '[%s][%s] %s',
                // 是否实时写入
                'realtime_write' => false,
            ],
            // 其它日志通道配置（示例Aliyun）
            'aliyun' => [
                // 日志记录方式
                'type'              => 'Aliyun',
                // 使用你的阿里云访问秘钥 AccessKeyId
                'access_key_id'     => '',
                // 使用你的阿里云访问秘钥 AccessKeySecret
                'access_key_secret' => '',
                // 创建的项目名称
                'project'           => '',
                // 选择与创建 project 所属区域匹配的 Endpoint
                'endpoint'          => '',
                // 创建的日志库名称
                'logstore'          => '',
                // 使用JSON格式记录（存储阿里云建议使用json方式，效果更好）
                'json'              => false,
                // 关闭通道日志写入
                'close'             => false,
                // 时间记录格式
                'time_format'       => 'c',
                // 日志输出格式化
                'format'            => '[%s][%s] %s',
            ],
        ],

    ];
```

用法
--

[](#用法)

```
    命名空间引用：
        use Topphp\TopphpLog\Log;
    调用方式有两种：
        1、通过原始句柄 handler 方法操作原始TP日志
            Log::handler($channel)->write("测试日志", "info");
        2、直接调用Topphp日志方法【简单的调用方式以及拥有更多拓展功能，推荐使用】
            Log::record("测试日志", "debug");
            Log::alert("测试级别日志", "", "", "aliyun");
            Log::write("测试日志（带请求数据）", "info", "订单服务", "支付操作");
        3、我们还可以自定义日志类型
            Log::diy("自定义一个日志类型");
            Log::handler("aliyun")->diy("自定义一个指定通道的日志类型");
    使用须知：
        1、使用多通道方式注意配置好对应的通道配置
        2、仅record方法的通道参数在第三位，write方法通道在第五位，其他方法通道参数均在第四位，这样做的目的是便于开发者调用方法方便
        3、默认的日志类已经集成了大部分TP日志方法，并提供兼容保障，更多用法可以参看TP的官方文档
```

修改日志
----

[](#修改日志)

有关最近更改的内容的详细信息，请参阅更改日志（[CHANGELOG](CHANGELOG.md)）。

测试
--

[](#测试)

```
    ./vendor/bin/phpunit tests/LogTest.php
```

贡献
--

[](#贡献)

详情请参阅贡献（[CONTRIBUTING](CONTRIBUTING.md)）和行为准则（[CODE\_OF\_CONDUCT](CODE_OF_CONDUCT.md)）。

安全
--

[](#安全)

如果您发现任何与安全相关的问题，请发送电子邮件至，而不要使用问题跟踪器。

信用
--

[](#信用)

- [topphp](https://github.com/topphp)
- [All Contributors](../../contributors)

许可证
---

[](#许可证)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 55.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

4

Last Release

2248d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3774ddafd6cc1dbff3db41386611fac2236c095e12c9e99f1717da35ad792087?d=identicon)[topphp](/maintainers/topphp)

---

Top Contributors

[![go-sleep](https://avatars.githubusercontent.com/u/100214298?v=4)](https://github.com/go-sleep "go-sleep (10 commits)")[![344147805](https://avatars.githubusercontent.com/u/26813709?v=4)](https://github.com/344147805 "344147805 (8 commits)")

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/topphp-topphp-log/health.svg)

```
[![Health](https://phpackages.com/badges/topphp-topphp-log/health.svg)](https://phpackages.com/packages/topphp-topphp-log)
```

###  Alternatives

[itsgoingd/clockwork

php dev tools in your browser

5.9k27.6M93](/packages/itsgoingd-clockwork)[bugsnag/bugsnag-psr-logger

Official Bugsnag PHP PSR Logger.

32132.5M2](/packages/bugsnag-bugsnag-psr-logger)[consolidation/log

Improved Psr-3 / Psr\\Log logger based on Symfony Console components.

15462.2M7](/packages/consolidation-log)[open-telemetry/api

API for OpenTelemetry PHP.

1833.0M214](/packages/open-telemetry-api)[codemix/yii2-streamlog

A Yii 2 log target for streams in URL format

531.4M6](/packages/codemix-yii2-streamlog)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
