Files
Socket/app/utils/Logger.php
T
OG Backup 2cd31285f0 backup: 线上最终版本全量备份
包含所有线上运行的改动:
- 荷官端倒计时卡顿修复(CountdownService TTL+10/前端watchdog)
- 停止下注debounce防重复(8个handle.js)
- 洗码量规则重写(单边/双边/开和不计/百家乐+龙虎)
- 龙虎和局不杀庄闲(全额退回)
- 日志系统(Logger工具类/日志查看/清理脚本)
- 好路提醒异常处理(WaybillRemindService try-catch)
- 扫牌器连接改进(ScanConnectService)
- 牛牛/三卡开牌修复
- .gitignore更新/.DS_Store清理
2026-06-14 14:20:43 +08:00

41 lines
1.4 KiB
PHP

<?php
namespace app\utils;
class Logger
{
const CAT_CONNECT = 'connect';
const CAT_GAME = 'game';
const CAT_BET = 'bet';
const CAT_ERROR = 'error';
const CAT_FRONTEND = 'frontend';
public static function log(string $category, string $level, string $message, array $context = []): void
{
$date = date('Y-m-d');
$time = date('Y-m-d H:i:s');
$dir = root_path() . 'runtime' . DIRECTORY_SEPARATOR . 'log' . DIRECTORY_SEPARATOR . $category;
if (!is_dir($dir)) {
mkdir($dir, 0755, true);
}
$file = $dir . DIRECTORY_SEPARATOR . $date . '.log';
$contextStr = $context ? ' ' . json_encode($context, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) : '';
$line = "[{$time}][{$level}] {$message}{$contextStr}" . PHP_EOL;
file_put_contents($file, $line, FILE_APPEND | LOCK_EX);
}
public static function info(string $category, string $message, array $context = []): void
{
self::log($category, 'INFO', $message, $context);
}
public static function warn(string $category, string $message, array $context = []): void
{
self::log($category, 'WARN', $message, $context);
}
public static function error(string $category, string $message, array $context = []): void
{
self::log($category, 'ERROR', $message, $context);
}
}