You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
AdLike2048/assets/mx/tools/DevLog.ts

35 lines
951 B

3 weeks ago
import { DEBUG, DEV, EDITOR } from 'cc/env';
let _verbose = false;
/** 开发跟踪日志总开关(默认关);控制台 `setDevLogVerbose(true)` */
export function setDevLogVerbose(enabled: boolean): void {
_verbose = enabled;
}
export function isDevLogVerbose(): boolean {
return _verbose && (DEBUG || DEV || EDITOR);
}
/** 去掉对象参数,避免 DevTools 展开 / 小游戏序列化开销 */
function _withoutObjects(args: unknown[]): unknown[] {
const out: unknown[] = [];
for (let i = 0; i < args.length; i++) {
const a = args[i];
if (a !== null && typeof a === 'object') continue;
out.push(a);
}
return out;
}
export function devLog(...args: unknown[]): void {
if (!isDevLogVerbose()) return;
console.log(..._withoutObjects(args));
}
try {
(globalThis as { setDevLogVerbose?: typeof setDevLogVerbose }).setDevLogVerbose = setDevLogVerbose;
} catch {
/* ignore */
}