imo-tikuwa/cakephp-operation-logs
Composer 安装命令:
composer require imo-tikuwa/cakephp-operation-logs
包简介
OperationLogs plugin for CakePHP
README 文档
README
Installation
You can install this plugin into your CakePHP application using composer.
The recommended way to install composer packages is:
# for CakePHP4
composer require imo-tikuwa/cakephp-operation-logs "2.*"
# for CakePHP3
composer require imo-tikuwa/cakephp-operation-logs "1.*"
How to Use
Load plugin to bootstrap.php
// cakephp 3.6 or less
Plugin::load('OperationLogs', ['bootstrap' => true]);
// cakephp 3.7 or higher
Application::addPlugin('OperationLogs', ['bootstrap' => true]);
or Application.php
public function bootstrap(): void
{
parent::bootstrap();
+ $this->addPlugin('OperationLogs', ['bootstrap' => true]);
}
Execute the database table initialization command.
※Executing the command will delete & create operation_logs, operation_logs_hourly, operation_logs_daily, operation_logs_monthly tables.
※If you want to record up to microseconds, specify the --enable_micro option.
cake init_operation_logs
Append middleware to Application.php
use OperationLogs\Middleware\OperationLogsMiddleware;
public function middleware($middlewareQueue)
{
$middlewareQueue
// Add operation_logs middleware.
->add(new OperationLogsMiddleware([
'exclude_urls' => [
'/debug-kit',
'/admin'
]
]))
;
return $middlewareQueue;
}
※If you want to log all requests without using the option, please replace with OperationLogsSimpleMiddleware middleware.
use OperationLogs\Middleware\OperationLogsSimpleMiddleware;
public function middleware($middlewareQueue)
{
$middlewareQueue
// Add operation_logs middleware.
->add(new OperationLogsSimpleMiddleware())
;
return $middlewareQueue;
}
Options.
| option name | option type | default | example | memo |
|---|---|---|---|---|
| mode | string | 'exclude' | 'include' | Only 'exclude' and 'include' allowed |
| exclude_urls | string array | [ '/debug-kit' ] | [ '/debug-kit', '/admin' ] | Exclude with prefix match |
| exclude_ips | string array | [] | [ '192.168', '::' ] | Exclude with prefix match |
| exclude_user_agents | string array | [] | [ 'Safari', 'Edge' ] | Exclude with broad match |
| include_urls | string array | [] | [ '/admin/top' ] | Include with prefix match |
| include_ips | string array | [] | [ '192.168.1.3' ] | Include with prefix match |
| include_user_agents | string array | [] | [ 'Firefox', 'Chrome' ] | Include with broad match |
※If 'mode' is 'exclude' the 'include_〇〇' option is ignored. (And vice versa)
CakePHP4.3以上のバージョンでPHPUnitテストを実施する場合
CakePHP4.3で実施されたFixtureのアップグレードに伴い、PHPUnitテストの際にスキーマファイルをロードする必要があります。
以下のような操作でOperationLogsプラグイン内に同梱するスキーマファイルをアプリケーション本体のschemaディレクトリにコピーすることができます。
composer require imo-tikuwa/cakephp-operation-logs "2.*"
composer run-script post-install-cmd --working-dir=vendor\imo-tikuwa\cakephp-operation-logs
Data summary commands.
daily_summaryコマンド、monthly_summaryコマンド、hourly_summaryコマンドがあります。
operation_logsテーブルのデータを元にクライアントIP、ユーザーエージェント、リクエストURLなどでグルーピングしたデータを集計します。
daily_summary command.
--target_ymdオプションで集計日を設定可能。
未指定のときは前日のデータを集計します。
データはoperation_logs_dailyテーブルに記録されます。
cake daily_summary --target_ymd=2020-02-13
monthly_summary command.
--target_ymオプションで集計年月を6桁の数字で設定可能。
未指定の時は先月のデータを集計します。
データはoperation_logs_monthlyテーブルに記録されます。
cake monthly_summary --target_ym=202002
hourly_summary command.
--target_ymdオプションで集計日を設定可能。
未指定の時は前日のデータを集計します。
1時間単位でデータを集計します。
データはoperation_logs_hourlyテーブルに記録されます。
cake hourly_summary --target_ymd=2020-02-13
imo-tikuwa/cakephp-operation-logs 适用场景与选型建议
imo-tikuwa/cakephp-operation-logs 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 314 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 02 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 imo-tikuwa/cakephp-operation-logs 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 imo-tikuwa/cakephp-operation-logs 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 314
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-02-21