apix/log
Composer 安装命令:
composer require apix/log
包简介
Minimalist, thin and fast PSR-3 compliant (multi-bucket) logger.
README 文档
README
APIx Log, very thin PSR-3 logger

Minimalist and fast PSR-3 compliant logger.
- Light, come out-of-the-box bundle with wrappers for:
- Extendable, additional logging backends are available:
- PHPMailer/apix-log-phpmailer ~ logs are sent using PHPMailer,
- jspalink/apix-log-pushover ~ logs are sent using Pushover,
- apix/log-tracker ~ adds logger/tracker such as Google Analytics, Dashbot, etc...,
- More contributions will be linked here.
- Clean API, see the
LoggerInterfaceand theLogFormatterInterface. - 100% Unit tested and compliant with PSR0, PSR1 and PSR2.
- Continuously integrated against 7.0, 8.x,
and HHVM(use ^1.1 for older PHP versions). - Available as a Composer
and as a PEARpackage.
Feel free to comment, send pull requests and patches...
🆕 Log dispatch can be postponed/accumulated using setDeferred().
Basic usage ~ standalone
$urgent_logger = new Apix\Log\Logger\Mail('franck@foo.bar'); $urgent_logger->setMinLevel('critical'); // catch logs >= to `critical`
This simple logger is now set to intercept critical, alert and emergency logs.
To log an event, use:
$urgent_logger->alert('Running out of {stuff}', ['stuff' => 'beers']);
Advanced usage ~ multi-logs dispatcher
Lets create an additional logger with purpose of catching log entries that have a severity level of warning or more -- see the log levels for the order.
$app_logger = new Apix\Log\Logger\File('/var/log/apix_app.log'); $app_logger->setMinLevel('warning') // intercept logs that are >= `warning` ->setCascading(false) // don't propagate to further buckets ->setDeferred(true); // postpone/accumulate logs processing
setCascading() was set to false (default is true) so the entries caught here won't continue downstream past that particular log bucket. setDeferred() was set to true (default is false) so processing happen on __destruct (end of script generally) rather than on the fly.
Now, lets create a main logger object and inject the two previous loggers.
// The main logger object (injecting an array of loggers) $logger = new Apix\Log\Logger( array($urgent_logger, $app_logger) );
Lets create an additional logger -- just for development/debug purposes.
if(DEBUG) { // Bucket for the remaining logs -- i.e. `notice`, `info` and `debug` $dev_logger = new Apix\Log\Logger\Stream(); // default to screen without output buffer // $dev_logger = new Logger\File('/tmp/apix_debug.log'); $dev_logger->setMinLevel('debug'); $logger->add($dev_logger); // another way to inject a log bucket }
Finally, lets push some log entries:
$e = new \Exception('Boo!'); // handled by both $urgent_logger & $app_logger $logger->critical('OMG saw {bad-exception}', [ 'bad-exception' => $e ]); // handled by $app_logger $logger->error($e); // push an object (or array) directly // handled by $dev_logger $logger->info('Testing a var {my_var}', array('my_var' => array(...)));
Log levels
The eight RFC 5424 levels of logs are supported, in cascading order:
| Severity | Description |
|---|---|
| Emergency | System level failure (not application level) |
| Alert | Failure that requires immediate attention |
| Critical | Serious failure at the application level |
| Error | Runtime errors, used to log unhandled exceptions |
| Warning | May indicate that an error will occur if action is not taken |
| Notice | Events that are unusual but not error conditions |
| Info | Normal operational messages (no action required) |
| Debug | Verbose info useful to developers for debugging purposes (default) |
Installation
Install the current major version using Composer with (recommended)
composer require apix/log:1.3.*
Or install the latest stable version with
composer require apix/log
License
APIx Log is licensed under the New BSD license -- see the LICENSE.txt for the full license details.
apix/log 适用场景与选型建议
apix/log 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.07M 次下载、GitHub Stars 达 51, 最近一次更新时间为 2014 年 09 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「log」 「logging」 「logger」 「psr」 「psr-3」 「apix」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 apix/log 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 apix/log 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 apix/log 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Zend Framework module that sets up Monolog for logging in applications.
Workflow logger
HTTP request logger middleware for Laravel
Asynchronous Sentry for Symfony - Fire and forget
Stackdriver handler for Monolog (codeinternetapplications/monolog-stackdriver Fork).
Laravel 5.x.x library for integration Monolog Sentry
统计信息
- 总下载量: 1.07M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 52
- 点击次数: 34
- 依赖项目数: 19
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2014-09-29