|
|
@@ -46,7 +46,6 @@
|
|
|
|
|
|
#### 2. 管理层 (Management)
|
|
|
- **UserLogCollectorManager**: 收集器管理器,统一调度所有收集器
|
|
|
-- **UserLogScheduleService**: 调度服务,提供同步和异步执行
|
|
|
- **UserLogService**: 对外服务接口
|
|
|
|
|
|
#### 3. 数据层 (Data)
|
|
|
@@ -181,61 +180,48 @@ if (!empty($userLogs)) {
|
|
|
|
|
|
## 配置系统
|
|
|
|
|
|
-### 主配置文件 (config/game_user_log.php)
|
|
|
+### 数据库配置
|
|
|
|
|
|
-```php
|
|
|
-return [
|
|
|
- // 全局开关
|
|
|
- 'enabled' => env('GAME_USER_LOG_ENABLED', true),
|
|
|
+用户日志系统的配置已迁移到数据库,存储在 `kku_game_configs` 表中,支持运行时动态修改。
|
|
|
|
|
|
- // 收集器配置
|
|
|
- 'collectors' => [
|
|
|
- 'max_records_per_run' => 1000, // 单次最大处理数
|
|
|
- 'collection_interval' => 2, // 收集间隔(秒)
|
|
|
-
|
|
|
- // 各模块开关
|
|
|
- 'fund' => ['enabled' => true],
|
|
|
- 'item' => ['enabled' => true],
|
|
|
- 'farm' => ['enabled' => true],
|
|
|
- 'point' => ['enabled' => true],
|
|
|
- ],
|
|
|
+#### 配置项说明
|
|
|
|
|
|
- // 性能配置
|
|
|
- 'performance' => [
|
|
|
- 'batch_size' => 100, // 批量处理大小
|
|
|
- 'use_queue' => true, // 是否使用队列
|
|
|
- 'cache_ttl' => 86400, // 缓存TTL
|
|
|
- ],
|
|
|
-
|
|
|
- // 清理配置
|
|
|
- 'cleanup' => [
|
|
|
- 'retention_days' => 30, // 保留天数
|
|
|
- 'auto_cleanup' => true, // 自动清理
|
|
|
- ],
|
|
|
-];
|
|
|
-```
|
|
|
+| 配置键 | 名称 | 类型 | 默认值 | 说明 |
|
|
|
+|--------|------|------|--------|------|
|
|
|
+| `user_log.enabled` | 用户日志系统启用 | 布尔值 | true | 控制整个用户日志系统是否启用 |
|
|
|
+| `user_log.auto_collect_enabled` | 自动收集日志启用 | 布尔值 | true | 控制是否允许自动收集用户日志 |
|
|
|
+| `user_log.max_records_per_run` | 单次最大处理记录数 | 整数 | 1000 | 每次收集日志时的最大处理记录数 |
|
|
|
+| `user_log.collection_interval` | 收集间隔 | 整数 | 2 | 日志收集的间隔时间(秒) |
|
|
|
+| `user_log.retention_days` | 日志保留天数 | 整数 | 30 | 用户日志的保留天数 |
|
|
|
+| `user_log.auto_cleanup` | 自动清理启用 | 布尔值 | true | 是否启用自动清理过期日志 |
|
|
|
|
|
|
-### 环境变量配置
|
|
|
+#### 配置访问方式
|
|
|
|
|
|
-```bash
|
|
|
-# 用户日志系统配置
|
|
|
-GAME_USER_LOG_ENABLED=true
|
|
|
-GAME_USER_LOG_MAX_RECORDS=1000
|
|
|
-GAME_USER_LOG_INTERVAL=2
|
|
|
-GAME_USER_LOG_RETENTION_DAYS=30
|
|
|
+```php
|
|
|
+use App\Module\Game\Services\GameConfigService;
|
|
|
|
|
|
-# 各模块开关
|
|
|
-GAME_USER_LOG_FUND_ENABLED=true
|
|
|
-GAME_USER_LOG_ITEM_ENABLED=true
|
|
|
-GAME_USER_LOG_FARM_ENABLED=true
|
|
|
-GAME_USER_LOG_POINT_ENABLED=true
|
|
|
+// 获取完整的用户日志配置
|
|
|
+$config = GameConfigService::getUserLogConfig();
|
|
|
|
|
|
-# 性能配置
|
|
|
-GAME_USER_LOG_BATCH_SIZE=100
|
|
|
-GAME_USER_LOG_USE_QUEUE=true
|
|
|
-GAME_USER_LOG_CACHE_TTL=86400
|
|
|
+// 配置结构示例
|
|
|
+[
|
|
|
+ 'enabled' => true,
|
|
|
+ 'auto_collect_enabled' => true,
|
|
|
+ 'max_records_per_run' => 1000,
|
|
|
+ 'collection_interval' => 2,
|
|
|
+ 'retention_days' => 30,
|
|
|
+ 'auto_cleanup' => true,
|
|
|
+]
|
|
|
```
|
|
|
|
|
|
+#### 后台管理
|
|
|
+
|
|
|
+可以通过后台管理界面修改配置:
|
|
|
+- 访问路径:`/admin/game-system-configs`
|
|
|
+- 支持在线修改配置值
|
|
|
+- 支持重置为默认值
|
|
|
+- 自动缓存管理
|
|
|
+
|
|
|
## 数据库设计
|
|
|
|
|
|
### 用户日志表 (kku_user_logs)
|
|
|
@@ -375,7 +361,7 @@ php artisan game:collect-user-logs --statistics
|
|
|
|
|
|
### Laravel 调度器配置
|
|
|
|
|
|
-在 `routes/console.php` 中添加:
|
|
|
+如需启用自动日志收集,可在 `routes/console.php` 中添加:
|
|
|
|
|
|
```php
|
|
|
use Illuminate\Support\Facades\Schedule;
|
|
|
@@ -387,6 +373,8 @@ Schedule::command('game:collect-user-logs --limit=100')->everyMinute();
|
|
|
Schedule::command('game:clean-expired-user-logs')->dailyAt('02:00');
|
|
|
```
|
|
|
|
|
|
+**注意**:默认情况下计划任务已被注释,需要根据实际需求启用。系统通过数据库配置 `user_log.auto_collect_enabled` 控制是否允许自动收集。
|
|
|
+
|
|
|
### Crontab 配置
|
|
|
|
|
|
如果需要更高频率的收集,可以直接配置 crontab:
|
|
|
@@ -397,83 +385,57 @@ Schedule::command('game:clean-expired-user-logs')->dailyAt('02:00');
|
|
|
* * * * * sleep 30; cd /path/to/project && php artisan game:collect-user-logs --limit=50 >/dev/null 2>&1
|
|
|
```
|
|
|
|
|
|
-### 队列处理器配置
|
|
|
+### 执行方式
|
|
|
|
|
|
-如果启用了队列处理,需要运行队列处理器:
|
|
|
+日志收集系统采用同步执行方式,通过命令行工具直接执行:
|
|
|
|
|
|
```bash
|
|
|
-# 启动队列处理器
|
|
|
-php artisan queue:work --queue=default --timeout=60
|
|
|
+# 手动执行日志收集
|
|
|
+php artisan game:collect-user-logs
|
|
|
|
|
|
-# 使用 Supervisor 管理队列处理器
|
|
|
-[program:laravel-queue-worker]
|
|
|
-process_name=%(program_name)s_%(process_num)02d
|
|
|
-command=php /path/to/project/artisan queue:work --queue=default --timeout=60
|
|
|
-directory=/path/to/project
|
|
|
-autostart=true
|
|
|
-autorestart=true
|
|
|
-user=www-data
|
|
|
-numprocs=2
|
|
|
+# 通过计划任务定时执行
|
|
|
+# 在 routes/console.php 中配置调度任务
|
|
|
```
|
|
|
|
|
|
## 监控和告警
|
|
|
|
|
|
### 健康检查
|
|
|
|
|
|
-系统提供完整的健康检查功能:
|
|
|
+系统提供基本的健康检查功能:
|
|
|
|
|
|
-```php
|
|
|
-// 通过服务调用
|
|
|
-$health = UserLogScheduleService::healthCheck();
|
|
|
+```bash
|
|
|
+# 检查收集器状态
|
|
|
+php artisan game:collect-user-logs --info
|
|
|
|
|
|
-// 返回结果示例
|
|
|
-[
|
|
|
- 'status' => 'healthy',
|
|
|
- 'checks' => [
|
|
|
- 'collectors_registered' => [
|
|
|
- 'status' => 'pass',
|
|
|
- 'count' => 4,
|
|
|
- 'details' => ['fund', 'item', 'farm', 'point']
|
|
|
- ],
|
|
|
- 'recent_logs' => [
|
|
|
- 'status' => 'info',
|
|
|
- 'count' => 156,
|
|
|
- 'message' => '最近10分钟生成了 156 条日志'
|
|
|
- ],
|
|
|
- 'database' => [
|
|
|
- 'status' => 'pass',
|
|
|
- 'message' => '数据库连接正常'
|
|
|
- ]
|
|
|
- ],
|
|
|
- 'timestamp' => '2025-06-13 11:16:04'
|
|
|
-]
|
|
|
+# 查看统计信息
|
|
|
+php artisan game:collect-user-logs --statistics
|
|
|
```
|
|
|
|
|
|
+通过命令行工具可以检查:
|
|
|
+- 收集器注册状态
|
|
|
+- 日志收集统计
|
|
|
+- 系统运行状态
|
|
|
+
|
|
|
### 性能监控
|
|
|
|
|
|
#### 收集统计
|
|
|
-```php
|
|
|
-// 获取收集统计信息
|
|
|
-$stats = UserLogScheduleService::getCollectionStats(7); // 最近7天
|
|
|
+```bash
|
|
|
+# 查看收集统计信息
|
|
|
+php artisan game:collect-user-logs --statistics
|
|
|
|
|
|
-// 返回结果
|
|
|
-[
|
|
|
- 'period' => '7天',
|
|
|
- 'start_date' => '2025-06-06',
|
|
|
- 'end_date' => '2025-06-13',
|
|
|
- 'total_logs' => 45678,
|
|
|
- 'daily_stats' => [
|
|
|
- '2025-06-06' => 6543,
|
|
|
- '2025-06-07' => 7234,
|
|
|
- // ...
|
|
|
- ],
|
|
|
- 'source_type_stats' => [
|
|
|
- 'fund' => 18765,
|
|
|
- 'item' => 12456,
|
|
|
- 'farm' => 8765,
|
|
|
- 'point' => 5692
|
|
|
- ]
|
|
|
-]
|
|
|
+# 输出示例
|
|
|
+📊 收集器统计信息:
|
|
|
+收集器数量: 5
|
|
|
+- fund: ⚙️ 资金日志收集器
|
|
|
+- item: ⚙️ 物品日志收集器
|
|
|
+- farm_harvest: 🌾 农场收获日志收集器
|
|
|
+- farm_upgrade: 🌾 农场升级日志收集器
|
|
|
+- point: ⭐ 积分日志收集器
|
|
|
+
|
|
|
+📋 用户日志表统计:
|
|
|
+ 📝 总日志数: 119163
|
|
|
+ 🕐 最新日志时间: 2025-06-22 23:35:56
|
|
|
+ 🕐 最旧日志时间: 2025-06-21 16:30:12
|
|
|
```
|
|
|
|
|
|
#### 执行时间监控
|
|
|
@@ -631,17 +593,15 @@ private function registerCollectors(): void
|
|
|
|
|
|
#### 3. 添加配置
|
|
|
|
|
|
-在 `config/game_user_log.php` 中添加配置:
|
|
|
+在数据库中添加配置项:
|
|
|
|
|
|
-```php
|
|
|
-'collectors' => [
|
|
|
- // ...
|
|
|
- 'custom' => [
|
|
|
- 'enabled' => env('GAME_USER_LOG_CUSTOM_ENABLED', true),
|
|
|
- ],
|
|
|
-],
|
|
|
+```sql
|
|
|
+INSERT INTO `kku_game_configs` (`key`, `name`, `description`, `group`, `type`, `value`, `default_value`, `sort_order`, `remark`) VALUES
|
|
|
+('user_log.custom_enabled', '自定义收集器启用', '控制自定义收集器是否启用', 'user_log', 1, '1', '1', 70, '');
|
|
|
```
|
|
|
|
|
|
+或通过后台管理界面添加配置项。
|
|
|
+
|
|
|
### 自定义消息模板
|
|
|
|
|
|
#### 1. 配置模板
|
|
|
@@ -728,12 +688,39 @@ Cache::remember("collector_progress:{$this->sourceType}", 300, function () {
|
|
|
|
|
|
#### 2. 配置缓存
|
|
|
```php
|
|
|
-// 缓存配置信息
|
|
|
-$config = Cache::remember('game_user_log_config', 3600, function () {
|
|
|
- return config('game_user_log');
|
|
|
-});
|
|
|
+// 配置自动缓存,通过GameConfigService访问
|
|
|
+$config = GameConfigService::getUserLogConfig();
|
|
|
+
|
|
|
+// 手动清除配置缓存(如果需要)
|
|
|
+GameConfigLogic::clearCache('user_log.enabled');
|
|
|
```
|
|
|
|
|
|
+## 系统清理说明
|
|
|
+
|
|
|
+### 已移除的废弃组件
|
|
|
+
|
|
|
+为了保持系统整洁,以下组件已被移除:
|
|
|
+
|
|
|
+#### 1. 废弃的配置文件
|
|
|
+- `config/game_user_log.php` - 配置已迁移到数据库
|
|
|
+
|
|
|
+#### 2. 废弃的服务类
|
|
|
+- `UserLogScheduleService` - 未被实际使用,功能已由命令行工具替代
|
|
|
+- `CollectUserLogJob` - 异步队列任务,未被实际使用
|
|
|
+
|
|
|
+#### 3. 废弃的protobuf类
|
|
|
+- `Request_RequestUserLogData` - 已被新命名空间替代
|
|
|
+- `Request_RequestUserClearLog` - 已被新命名空间替代
|
|
|
+
|
|
|
+### 迁移说明
|
|
|
+
|
|
|
+如果您的代码中引用了上述废弃组件,请按以下方式迁移:
|
|
|
+
|
|
|
+1. **配置访问**:使用 `GameConfigService::getUserLogConfig()` 替代文件配置
|
|
|
+2. **日志收集**:直接使用 `CollectUserLogsCommand` 或 `UserLogCollectorManager`
|
|
|
+3. **异步处理**:如需异步处理,可以自行实现队列任务调用 `UserLogCollectorManager`
|
|
|
+4. **protobuf类**:使用新的命名空间下的类
|
|
|
+
|
|
|
## 故障排除
|
|
|
|
|
|
### 常见问题
|