1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- function printStack(){
- const stack = new Error().stack;
- console.log("调用堆栈:",stack);
- }
- const originalConsoleLog = console.log;
- function isHighSurrogate(codeUnit) {
- return codeUnit >= 0xD800 && codeUnit <= 0xDBFF;
- }
- function isLowSurrogate(codeUnit) {
- return codeUnit >= 0xDC00 && codeUnit <= 0xDFFF;
- }
- function splitAndPrintString(str, maxSize) {
- // if(str.indexOf(`{"optionInfo":[{"amount`)!=-1){
- // printStack();
- // }
- let strLength = str.length;
- for (let i = 0; i < strLength; i += maxSize) {
- let end = i + maxSize;
- // 确保不要在代理对中间拆分
- if (end < str.length && isHighSurrogate(str.charCodeAt(end - 1)) && isLowSurrogate(str.charCodeAt(end))) {
- end++;
- }
- if (strLength > maxSize) {//超过1页
- if (i === 0) { // 第一段
- originalConsoleLog(str.slice(i, end), "__>>__");
- } else if (end >= strLength) { // 最后一段
- originalConsoleLog("__<<__", str.slice(i, end));
- } else { // 中间的段
- originalConsoleLog("__<<__", str.slice(i, end), "__>>__");
- }
- } else {
- originalConsoleLog(str.slice(i, end));
- }
- }
- }
- //重新定义console.log方法
- console.log = function (...args) {
- const maxChunkSize = 800; // 设定最大字符数,可根据需要调整
- // 将所有参数转换为字符串并拼接
- const combinedString = args.map(arg => {
- if (typeof arg === 'object') {
- try {
- return JSON.stringify(arg);
- } catch (e) {
- return "啊啊啊啊啊,解析失败了" + e.message;
- }
- } else {
- return String(arg);
- }
- }).join(' ');
- // 分段打印处理过的字符串
- splitAndPrintString(combinedString, maxChunkSize);
- };
|