PHPackages                             agarage/ulog - 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. agarage/ulog

ActiveLibrary

agarage/ulog
============

A PHP Logger

3261PHP

Since May 9Pushed 10y ago1 watchersCompare

[ Source](https://github.com/jasonz93/ulog)[ Packagist](https://packagist.org/packages/agarage/ulog)[ RSS](/packages/agarage-ulog/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

ULog
====

[](#ulog)

PHP日志组件，可以使用多种存储方式记录日志，并且可以自由扩展。

使用方法
----

[](#使用方法)

```
use AGarage\ULog\ULog as ULog;
use AGarage\ULog\Writer\DoctrineStorage as DoctrineStorage;
use Psr\Log\LogLevel as LogLevel;

$config = [
    'host' => 'localhost',
    'service' => 'ULog test',
    'storages' => [
        [
            'class' => 'AGarage\ULog\Storage\SingleFileStorage',
            'level' => ULog::INFO,
            'path' => '/tmp/ulog.log'
        ]
    ]
];

//初始化单例模式ULog
ULog::initialize($config);
//获取单例模式ULog
$logger = ULog::getLogger();

$anotherLogger = new ULog($config);

//初始化一个数据库连接用于ULog
$conn = \Doctrine\DBAL\DriverManager::getConnection([
    'driver' => 'pdo_mysql',
    'host' => 'localhost',
    'user' => 'root',
    'password' => '123456',
    'dbname' => 'app',
    'charset' => 'utf8'
]);

//创建一个DoctrineStorage
$storage = new DoctrineStorage([
    'level' => LogLevel::INFO
]);
//为DoctrineStorage设置数据库连接
$storage->setConnection($conn);

//向ULog添加Storage
$logger->addStorage($storage);

$logger->info('This log will be written by storages in $logger.');
$anotherLogger->debug('This log will not written by storages in $anotherLogger.');
```

配置说明
----

[](#配置说明)

### ULog

[](#ulog-1)

```
[
    'host' => 'localhost',  //产生日志的主机名（默认localhost）
    'service' => 'ULog'     //产生日志的服务名（默认ULog）
    'storages' => [          //Writers
        [
            'class' => 'AGarage\ULog\Storage\SingleFileStorage',  //Storage的类名（必须）
            'level' => LogLevel::INFO   //大于该等级的日志将被记录（默认DEBUG）
            'path' => '/tmp/ulog.log'   //日志文件路径（必须）
        ]
    ]
]
```

### Storages

[](#storages)

#### SingleFileStorage

[](#singlefilestorage)

使用单个文本日志文件记录日志

```
[
    'class' => 'AGarage\ULog\Storage\SingleFileStorage',  //Writer的类名（必须）
    'level' => LogLevel::INFO   //大于该等级的日志将被记录（默认DEBUG）
    'path' => '/tmp/ulog.log'   //日志文件路径（必须）
]
```

#### DoctrineStorage

[](#doctrinestorage)

使用Doctrine记录日志

```
[
    'class' => 'AGarage\ULog\Storage\DoctrineStorage',
    'level' => LogLevel::INFO   //默认DEBUG
]
```

初始化该类型Storage后需要调用`setConnection`方法为其设置数据库连接

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/bfe129d759069cd557b2d6c6ad84605ed02c3c090ce197acf1fa1b7973fb448c?d=identicon)[jasonz93](/maintainers/jasonz93)

---

Top Contributors

[![jasper-zsh](https://avatars.githubusercontent.com/u/9486306?v=4)](https://github.com/jasper-zsh "jasper-zsh (1 commits)")

### Embed Badge

![Health badge](/badges/agarage-ulog/health.svg)

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

PHPackages © 2026

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