blueant-allan / elasticlogger
Cloudstaff的CakePHP自定义日志插件
1.0
2021-02-11 08:11 UTC
Requires
- cakephp/cakephp: ^3.5
README
这是一个用于创建自定义日志的CakePHP插件。使用CakePHP版本3.x
安装
您可以使用composer将此插件安装到您的CakePHP应用程序中。
安装composer包的推荐方法是
composer require blueant-allan/ElasticLogger
配置
- 在您的项目中将包安装完成后。您需要在src/Application.php中的bootstrap方法中添加以下代码以加载插件。
public function bootstrap() { // you loaded plugins here $this->addPlugin('ElasticLogger'); }
- 要开始使用此插件,请在控制器中的initialize()方法中加载组件,如下所示
public function initialize(): void { parent::initialize(); // more of your controller initialize code here $this->loadComponent('ElasticLogger.Logcentral'); }
用法
该组件将期望以下参数
- 事件类型:可以用来描述写入日志的事件类型
- 消息内容:您的日志消息内容
- (可选)此第三个参数是可选的。如果您需要传递对象或数组,您可以使用此第三个参数将对象或数组添加到日志中
创建活动信息日志
$this->Logcentral->activityInfo('EventType', 'your message');
创建活动调试日志
$this->Logcentral->activityDebug('EventType', 'your message');
创建活动错误日志
$this->Logcentral->activityError('EventType', 'your message');
创建活动通知日志
$this->Logcentral->activityNotice('EventType', 'your message');
创建活动警告日志
$this->Logcentral->activityWarning('EventType', 'your message');
向日志传递数组。以下是一个示例
$data = [ 'id' => 42, 'name' => 'Mark Tune', 'roles' => ['Admin', 'Support'] ]; $this->Logcentral->activityInfo('Login', 'User successfully logged in', $data);