Files
Socket/public/static/handle/js/error-report.js
T
testadmin d77c6beac7 feat: add logging module for backend + frontend error reporting
Backend:
- New Logger utility (app/utils/Logger.php) with category-based log files
  (connect/game/bet/error/frontend under runtime/log/)
- Log WebSocket connect/close events (WsConnect, WsClose)
- Log dealer auth success/failure (SpaceConnectService)
- Log all game events: startBet, endBet, changeBoot, opening for all 7 game types
- Log unhandled exceptions (ExceptionHandle)
- Separate SQL/error logs via apart_level, enable realtime_write for Swoole
- Add /log/report POST endpoint for frontend error ingestion

Frontend:
- New error-report.js with window.onerror + unhandledrejection auto-reporting
- Added to all 12 dealer HTML templates
- Bump VERSION_V to v10.1.0
2026-05-14 11:28:33 +08:00

48 lines
1.4 KiB
JavaScript

(function() {
var reportUrl = '/log/report';
var queue = [];
var sending = false;
function send(data) {
if (queue.length >= 10) return;
data.source = 'handle';
data.time = new Date().toISOString();
data.url = location.href;
queue.push(data);
flush();
}
function flush() {
if (sending || queue.length === 0) return;
sending = true;
var item = queue.shift();
var xhr = new XMLHttpRequest();
xhr.open('POST', reportUrl);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onloadend = function() { sending = false; flush(); };
xhr.onerror = function() { sending = false; };
xhr.timeout = 3000;
xhr.send(JSON.stringify(item));
}
window.onerror = function(message, source, lineno, colno, error) {
send({
type: 'error',
message: String(message),
stack: error && error.stack ? error.stack.substring(0, 2000) : '',
file: source,
line: lineno,
col: colno
});
};
window.addEventListener('unhandledrejection', function(event) {
var reason = event.reason;
send({
type: 'unhandledrejection',
message: reason && reason.message ? reason.message : String(reason),
stack: reason && reason.stack ? reason.stack.substring(0, 2000) : ''
});
});
})();