joefallon / phplog
此包包含一个简单的PSR logger,最小化行长度。
v3.1.2
2015-12-27 22:47 UTC
Requires
- php: >=5.3.0
- psr/log: ^1.0
Requires (Dev)
- joefallon/kisstest: ^2.0
- joefallon/phpautoloader: ^2.0
README
由 Joe Fallon 提供
这是一个简单的日志库。它具有以下特性
- 完整的单元测试套件。
- 它可以集成到任何现有的项目中。
- 只需几分钟即可完全理解。
- 每行日志文本都包含最少的冗余前缀。
- 完全符合 psr/log。
安装
使用 Composer 安装 PhpDatabase 是最简单的方法。创建以下 composer.json
文件并运行 php composer.phar install
命令以安装它。
{ "require": { "joefallon/phplog": "*" } }
用法
此库中包含一个名为 Log
的类。它包含以下方法
__construct($filePath, $level) emergency($message, array $context = array()) alert($message, array $context = array()) critical($message, array $context = array()) error($message, array $context = array()) warning($message, array $context = array()) notice($message, array $context = array()) info($message, array $context = array()) debug($message, array $context = array()) log($level, $message, array $context = array())
带有上下文的示例日志条目看起来像这样
2015-02-05 10:35:20 [DEBUG] Test debug. {"contextKey":"contextVal"}
2015-02-05 10:35:20 [INFO] Test info. {"contextKey":"contextVal"}
2015-02-05 10:35:20 [LOG] Test notice. {"contextKey":"contextVal"}
2015-02-05 10:35:20 [WARN] Test warning. {"contextKey":"contextVal"}
2015-02-05 10:35:20 [ERROR] Test error. {"contextKey":"contextVal"}
2015-02-05 10:35:20 [CRITICAL] Test critical. {"contextKey":"contextVal"}
2015-02-05 10:35:20 [ALERT] Test alert. {"contextKey":"contextVal"}
2015-02-05 10:35:20 [EMERGENCY] Test emergency. {"contextKey":"contextVal"}
2015-02-05 10:35:20 [ALERT] Test off message. {"contextKey":"contextVal"}
不带上下文的示例日志条目看起来像这样
2015-02-05 10:35:20 [DEBUG] Test debug.
2015-02-05 10:35:20 [INFO] Test info.
2015-02-05 10:35:20 [LOG] Test notice.
2015-02-05 10:35:20 [WARN] Test warning.
2015-02-05 10:35:20 [ERROR] Test error.
2015-02-05 10:35:20 [CRITICAL] Test critical.
2015-02-05 10:35:20 [ALERT] Test alert.
2015-02-05 10:35:20 [EMERGENCY] Test emergency.
2015-02-05 10:35:20 [ALERT] Test off message.
打开日志并写入调试消息
$logger = new Log('/tests/logs/' . date('Y-m-d') . '.log', Log::DEBUG); $logger->debug('Test debug.', array('contextKey' => 'contextVal'));