Compare commits

...
2 Commits
Author SHA1 Message Date
testadmin 3bac9960b8 refine: normalize bet log names and init_table_fail level 2026-05-14 11:50:59 +08:00
testadmin a180fe8385 feat: complete logging audit - fill all gaps
- Filter noisy audio play() errors from frontend log
- Add logging to ALL 8 ToBet services (was only Baccarat)
- Add InitTableService logging (Sumday/Boot/NumberTab creation & failure)
- Add logview.sh for quick log viewing
- Add log_cleanup.sh for 30-day rotation
2026-05-14 11:49:36 +08:00
10 changed files with 124 additions and 6 deletions
+4
View File
@@ -3,6 +3,7 @@
namespace app\services\bet;
use app\models\bet\Bet;
use app\utils\Logger;
use freedom\utils\DiceUtil;
use freedom\utils\SocketSession;
@@ -33,6 +34,7 @@ class ToBetDiceService{
$time = time();
$toBetCheck = ToBetCommonService::toBetCheck($tableInfo,$event,$data);
if ($toBetCheck['status'] == false){
Logger::warn(Logger::CAT_BET, 'dice_bet_fail', ['table_id' => $tableInfo['id'], 'msg' => $toBetCheck['msg']]);
$ws->emit('toBet',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => $toBetCheck['msg']]);
SocketSession::resetRepeat($fd,'user','isToBet');
return;
@@ -90,6 +92,7 @@ class ToBetDiceService{
$res = Bet::toBet($tableInfo,$userInfo,$numberTabInfo,$prevBetInfo,$data,$seat_num,$betTotalAmount,$time,0);
$numberTabAmount = string_to_array($numberTabInfo['dice_amount']);
if($res){
Logger::info(Logger::CAT_BET, 'dice_bet_success', ['user_id' => $userInfo['id'], 'table_id' => $tableInfo['id'], 'amount' => $amount]);
$ws->emit('toBet',['status' => true, 'table_id' => $tableInfo['id'], 'bet_amount_msg' => $betTotalAmount, 'money' => ($userInfo['money'] - $amount),'seat_num' => $seat_num, 'msg' => 'to_bet_success']);
$totalAmountArray = DiceUtil::amountInc($numberTabAmount, $data);
$round = [
@@ -98,6 +101,7 @@ class ToBetDiceService{
];
$ws->to(SocketSession::HOUSE_NAME)->emit('allBetAmount',['status' => true, 'table_id' => $tableInfo['id'], 'round' => $round]);
}else{
Logger::warn(Logger::CAT_BET, 'dice_bet_db_fail', ['user_id' => $userInfo['id'], 'table_id' => $tableInfo['id'], 'amount' => $amount]);
$ws->emit('toBet',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'to_bet_fail']);
}
SocketSession::resetRepeat($fd,'user','isToBet');
+4
View File
@@ -5,6 +5,7 @@ namespace app\services\bet;
use app\models\bet\Bet;
use app\utils\Logger;
use freedom\utils\SocketSession;
/**
@@ -32,6 +33,7 @@ class ToBetDtService
$time = time();
$toBetCheck = ToBetCommonService::toBetCheck($tableInfo,$event,$data);
if ($toBetCheck['status'] == false){
Logger::warn(Logger::CAT_BET, 'dt_bet_fail', ['table_id' => $tableInfo['id'], 'msg' => $toBetCheck['msg']]);
$ws->emit('toBet',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => $toBetCheck['msg']]);
SocketSession::resetRepeat($fd,'user','isToBet');
return;
@@ -107,6 +109,7 @@ class ToBetDtService
$res = Bet::toBet($tableInfo,$userInfo,$numberTabInfo,$prevBetInfo,$data,$seat_num,$betTotalAmount,$time,0);
if($res){
Logger::info(Logger::CAT_BET, 'dt_bet_success', ['user_id' => $userInfo['id'], 'table_id' => $tableInfo['id'], 'amount' => $amount]);
$ws->emit('toBet',['status' => true, 'table_id' => $tableInfo['id'], 'bet_amount_msg' => $betTotalAmount, 'money' => ($userInfo['money'] - $amount),'seat_num' => $seat_num, 'msg' => 'to_bet_success']);
if($userInfo['bet_type'] == 2){
$tableManager = app('swoole.table.manager');
@@ -128,6 +131,7 @@ class ToBetDtService
);
$ws->to(SocketSession::HOUSE_NAME)->emit('allBetAmount',['status' => true, 'table_id' => $tableInfo['id'], 'round' => $round]);
}else{
Logger::warn(Logger::CAT_BET, 'dt_bet_db_fail', ['user_id' => $userInfo['id'], 'table_id' => $tableInfo['id'], 'amount' => $amount]);
$ws->emit('toBet',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'to_bet_fail']);
}
SocketSession::resetRepeat($fd,'user','isToBet');
+4
View File
@@ -4,6 +4,7 @@
namespace app\services\bet;
use app\models\bet\Bet;
use app\utils\Logger;
use freedom\utils\SocketSession;
/**
@@ -49,6 +50,7 @@ class ToBetNnService
$time = time();
$toBetCheck = ToBetCommonService::toBetCheck($tableInfo,$event,$data);
if ($toBetCheck['status'] == false){
Logger::warn(Logger::CAT_BET, 'nn_bet_fail', ['table_id' => $tableInfo['id'], 'msg' => $toBetCheck['msg']]);
$ws->emit('toBet',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => $toBetCheck['msg']]);
SocketSession::resetRepeat($fd,'user','isToBet');
return;
@@ -181,9 +183,11 @@ class ToBetNnService
$res = Bet::toBet($tableInfo,$userInfo,$numberTabInfo,$prevBetInfo,$data,$seat_num,$betTotalAmount,$time,0);
if($res){
Logger::info(Logger::CAT_BET, 'nn_bet_success', ['user_id' => $userInfo['id'], 'table_id' => $tableInfo['id'], 'amount' => $amount]);
$ws->emit('toBet',['status' => true, 'table_id' => $tableInfo['id'], 'bet_amount_msg' => $betTotalAmount, 'money' => ($userInfo['money'] - $amount),'seat_num' => $seat_num, 'msg' => 'to_bet_success']);
// 待确定是否推送即时彩池,现不推送
}else{
Logger::warn(Logger::CAT_BET, 'nn_bet_db_fail', ['user_id' => $userInfo['id'], 'table_id' => $tableInfo['id'], 'amount' => $amount]);
$ws->emit('toBet',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'to_bet_fail']);
}
SocketSession::resetRepeat($fd,'user','isToBet');
@@ -3,6 +3,7 @@
namespace app\services\bet;
use app\models\bet\Bet;
use app\utils\Logger;
use freedom\utils\RouletteUtil;
use freedom\utils\SocketSession;
@@ -36,6 +37,7 @@ class ToBetRouletteService{
$time = time();
$toBetCheck = ToBetCommonService::toBetCheck($tableInfo,$event,$data);
if ($toBetCheck['status'] == false){
Logger::warn(Logger::CAT_BET, 'roulette_bet_fail', ['table_id' => $tableInfo['id'], 'msg' => $toBetCheck['msg']]);
$ws->emit('toBet',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => $toBetCheck['msg']]);
SocketSession::resetRepeat($fd,'user','isToBet');
return;
@@ -54,6 +56,7 @@ class ToBetRouletteService{
$res = Bet::toBet($tableInfo,$userInfo,$numberTabInfo,$prevBetInfo,$data,$seat_num,$betTotalAmount,$time,0,$fieldName);
$numberTabAmount = string_to_array($numberTabInfo[$fieldName]);
if($res){
Logger::info(Logger::CAT_BET, 'roulette_bet_success', ['user_id' => $userInfo['id'], 'table_id' => $tableInfo['id'], 'amount' => $amount]);
$ws->emit('toBet',['status' => true, 'table_id' => $tableInfo['id'], 'bet_amount_msg' => [$fieldName => $betTotalAmount], 'money' => ($userInfo['money'] - $amount),'seat_num' => $seat_num, 'msg' => 'to_bet_success']);
$totalAmountArray = RouletteUtil::amountInc($numberTabAmount, $data);
$round = [
@@ -62,6 +65,7 @@ class ToBetRouletteService{
];
$ws->to(SocketSession::HOUSE_NAME)->emit('allBetAmount',['status' => true, 'table_id' => $tableInfo['id'], 'round' => $round]);
}else{
Logger::warn(Logger::CAT_BET, 'roulette_bet_db_fail', ['user_id' => $userInfo['id'], 'table_id' => $tableInfo['id'], 'amount' => $amount]);
$ws->emit('toBet',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'to_bet_fail']);
}
SocketSession::resetRepeat($fd,'user','isToBet');
+4
View File
@@ -4,6 +4,7 @@
namespace app\services\bet;
use app\models\bet\Bet;
use app\utils\Logger;
use freedom\utils\SocketSession;
/**
@@ -50,6 +51,7 @@ class ToBetTcService
$time = time();
$toBetCheck = ToBetCommonService::toBetCheck($tableInfo,$event,$data);
if ($toBetCheck['status'] == false){
Logger::warn(Logger::CAT_BET, 'tc_bet_fail', ['table_id' => $tableInfo['id'], 'msg' => $toBetCheck['msg']]);
$ws->emit('toBet',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => $toBetCheck['msg']]);
SocketSession::resetRepeat($fd,'user','isToBet');
return;
@@ -182,9 +184,11 @@ class ToBetTcService
$res = Bet::toBet($tableInfo,$userInfo,$numberTabInfo,$prevBetInfo,$data,$seat_num,$betTotalAmount,$time,0);
if($res){
Logger::info(Logger::CAT_BET, 'tc_bet_success', ['user_id' => $userInfo['id'], 'table_id' => $tableInfo['id'], 'amount' => $amount]);
$ws->emit('toBet',['status' => true, 'table_id' => $tableInfo['id'], 'bet_amount_msg' => $betTotalAmount, 'money' => ($userInfo['money'] - $amount),'seat_num' => $seat_num, 'msg' => 'to_bet_success']);
// 待确定是否推送即时彩池,现不推送
}else{
Logger::warn(Logger::CAT_BET, 'tc_bet_db_fail', ['user_id' => $userInfo['id'], 'table_id' => $tableInfo['id'], 'amount' => $amount]);
$ws->emit('toBet',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'to_bet_fail']);
}
SocketSession::resetRepeat($fd,'user','isToBet');
+4
View File
@@ -4,6 +4,7 @@
namespace app\services\bet;
use app\models\bet\Bet;
use app\utils\Logger;
use freedom\utils\SocketSession;
/**
@@ -36,6 +37,7 @@ class ToBetToningService
$time = time();
$toBetCheck = ToBetCommonService::toBetCheck($tableInfo,$event,$data);
if ($toBetCheck['status'] == false){
Logger::warn(Logger::CAT_BET, 'toning_bet_fail', ['table_id' => $tableInfo['id'], 'msg' => $toBetCheck['msg']]);
$ws->emit('toBet',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => $toBetCheck['msg']]);
SocketSession::resetRepeat($fd,'user','isToBet');
return;
@@ -89,6 +91,7 @@ class ToBetToningService
$res = Bet::toBet($tableInfo,$userInfo,$numberTabInfo,$prevBetInfo,$data,$seat_num,$betTotalAmount,$time,0);
$numberTabAmount = string_to_array($numberTabInfo['toning_amount']);
if($res){
Logger::info(Logger::CAT_BET, 'toning_bet_success', ['user_id' => $userInfo['id'], 'table_id' => $tableInfo['id'], 'amount' => $amount]);
$ws->emit('toBet',['status' => true, 'table_id' => $tableInfo['id'], 'bet_amount_msg' => $betTotalAmount, 'money' => ($userInfo['money'] - $amount),'seat_num' => $seat_num, 'msg' => 'to_bet_success']);
$round = array(
'toning_zero' => isset($numberTabAmount['toning_zero']) ? intval($numberTabAmount['toning_zero'] + $data['toning_zero']) : $data['toning_zero'],
@@ -113,6 +116,7 @@ class ToBetToningService
);
$ws->to(SocketSession::HOUSE_NAME)->emit('allBetAmount',['status' => true, 'table_id' => $tableInfo['id'], 'round' => $round]);
}else{
Logger::warn(Logger::CAT_BET, 'toning_bet_db_fail', ['user_id' => $userInfo['id'], 'table_id' => $tableInfo['id'], 'amount' => $amount]);
$ws->emit('toBet',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'to_bet_fail']);
}
SocketSession::resetRepeat($fd,'user','isToBet');
+16 -6
View File
@@ -7,6 +7,7 @@ namespace app\services\connect;
use app\models\process\Boot;
use app\models\process\NumberTab;
use app\models\process\Sumday;
use app\utils\Logger;
/**
* TODO 桌子状态服务
@@ -22,15 +23,24 @@ class InitTableService
*/
public static function initTable(array $tableInfo): array
{
//查询日结
$lastSumday = Sumday::getByTableIdOrderByIdDesc($tableInfo);
if (!$lastSumday) $lastSumday = Sumday::addByTable($tableInfo);
//查询靴
if (!$lastSumday) {
$lastSumday = Sumday::addByTable($tableInfo);
Logger::info(Logger::CAT_GAME, 'init_create_sumday', ['table_id' => $tableInfo['id']]);
}
$lastBoot = Boot::getByTableIdOrderByIdDesc($tableInfo);
if (!$lastBoot) $lastBoot = Boot::addBySumday($lastSumday);
//查询铺
if (!$lastBoot) {
$lastBoot = Boot::addBySumday($lastSumday);
Logger::info(Logger::CAT_GAME, 'init_create_boot', ['table_id' => $tableInfo['id'], 'sumday_id' => $lastSumday['id'] ?? '']);
}
$lastNumberTab = NumberTab::getByBootIdOrderByIdDesc($lastBoot);
if (!$lastNumberTab) $lastNumberTab = NumberTab::addByBoot($lastBoot);
if (!$lastNumberTab) {
$lastNumberTab = NumberTab::addByBoot($lastBoot);
Logger::info(Logger::CAT_GAME, 'init_create_number_tab', ['table_id' => $tableInfo['id'], 'boot_id' => $lastBoot['id'] ?? '']);
}
if (!$lastNumberTab) {
Logger::warn(Logger::CAT_GAME, 'init_table_fail', ['table_id' => $tableInfo['id'], 'table_name' => $tableInfo['table_name'] ?? '']);
}
return $lastNumberTab;
}
+6
View File
@@ -0,0 +1,6 @@
#!/bin/bash
# OG 日志清理 - 删除30天前的日志文件
LOG_DIR="/www/wwwroot/Socket/runtime/log"
find "$LOG_DIR" -name "*.log" -type f -mtime +30 -delete 2>/dev/null
find "$LOG_DIR" -type d -empty -delete 2>/dev/null
echo "[$(date)] log cleanup done, current size: $(du -sh $LOG_DIR | cut -f1)"
Executable
+63
View File
@@ -0,0 +1,63 @@
#!/bin/bash
# OG 日志快速查看工具
# 用法: ./logview.sh [分类] [选项]
# 分类: frontend | game | connect | bet | error | all
# 选项: -f 实时跟踪 | -t N 查看最后N行 | -g "关键词" 搜索
#
# 示例:
# ./logview.sh frontend # 查看今天的前端错误
# ./logview.sh game -f # 实时跟踪游戏事件
# ./logview.sh game -g "table_id.*12" # 搜索805牛牛台
# ./logview.sh connect -t 50 # 最近50条连接日志
# ./logview.sh all -g "WARN\|ERROR" # 所有分类的警告和错误
# ./logview.sh frontend -d 2026-05-13 # 查看指定日期
LOG_DIR="/www/wwwroot/Socket/runtime/log"
DATE=$(date +%Y-%m-%d)
CATEGORY=${1:-all}
shift 2>/dev/null
MODE="tail"
LINES=30
GREP=""
CUSTOM_DATE=""
while [[ $# -gt 0 ]]; do
case $1 in
-f) MODE="follow"; shift ;;
-t) LINES=$2; shift 2 ;;
-g) GREP=$2; shift 2 ;;
-d) CUSTOM_DATE=$2; shift 2 ;;
*) shift ;;
esac
done
[[ -n "$CUSTOM_DATE" ]] && DATE=$CUSTOM_DATE
if [[ "$CATEGORY" == "all" ]]; then
CATS="frontend game connect bet error"
else
CATS=$CATEGORY
fi
for cat in $CATS; do
FILE="$LOG_DIR/$cat/$DATE.log"
if [[ ! -f "$FILE" ]]; then
echo "[$cat] 无日志: $FILE"
continue
fi
if [[ "$MODE" == "follow" ]]; then
echo "=== 实时跟踪 $cat ==="
tail -f "$FILE"
exit 0
fi
echo "=== $cat ($DATE) ==="
if [[ -n "$GREP" ]]; then
grep -i "$GREP" "$FILE" | tail -$LINES
else
tail -$LINES "$FILE"
fi
echo
done
+15
View File
@@ -2,9 +2,24 @@
var reportUrl = '/log/report';
var queue = [];
var sending = false;
var ignorePatterns = [
'play() request was interrupted',
'The play() request was interrupted',
'NotAllowedError',
'AbortError'
];
function shouldIgnore(msg) {
if (!msg) return false;
for (var i = 0; i < ignorePatterns.length; i++) {
if (msg.indexOf(ignorePatterns[i]) !== -1) return true;
}
return false;
}
function send(data) {
if (queue.length >= 10) return;
if (shouldIgnore(data.message)) return;
data.source = 'handle';
data.time = new Date().toISOString();
data.url = location.href;