fabcam / console-logger
CakePHP 控制台日志插件
v1.1
2018-05-09 19:04 UTC
Requires
- cakephp/cakephp: ^3.4
Requires (Dev)
- phpunit/phpunit: ^5.7|^6.0
This package is not auto-updated.
Last update: 2024-09-24 22:25:20 UTC
README
#CakePHP 控制台日志插件
将任何您想记录的内容记录到控制台。
用法
导入 Logger
use ConsoleLogger\Log\Logger;
然后
Logger::log('message', 'info');
log 函数可以接收一个数组、对象或字符串作为消息。第二个参数是级别,通常用于样式。
有一些预定义的级别
$output->styles('annoy', ['text' => 'yellow', 'blink' => true]);
$output->styles('http_response', ['text' => 'yellow']);
$output->styles('http_request', ['text' => 'cyan']);
还有一些在 Cake 的 ConsoleOutput 类中定义
protected static $_styles = [
'emergency' => ['text' => 'red'],
'alert' => ['text' => 'red'],
'critical' => ['text' => 'red'],
'error' => ['text' => 'red'],
'warning' => ['text' => 'yellow'],
'info' => ['text' => 'cyan'],
'debug' => ['text' => 'yellow'],
'success' => ['text' => 'green'],
'comment' => ['text' => 'blue'],
'question' => ['text' => 'magenta'],
'notice' => ['text' => 'cyan']
];
有一个基控制器可以用来记录每个动作。在您的 AppController 中
...
use ConsoleLogger\Controller\BaseController;
class AppController extends BaseController
{
...
还有一个针对 HttpClient 类的包装器,它可以记录每个 HTTP 方法的请求和响应。而不是使用 Cake 的 HttpClient,您可以使用
use ConsoleLogger\Http\Client;
一个行为也被包含在内,以便在 BeforeFind 回调中记录执行的每个查询。为了使用它,只需将以下行添加到所需的 Table
$this->addBehavior('ConsoleLogger.Log')
安装
您可以使用 composer 将此插件安装到您的 CakePHP 应用程序中。
安装 composer 包的推荐方法是
composer require fabcam/console-logger