onConsole 仅 debug 生效,release 零日志开销
H5 console 转发开关固化为构造期 DEBUG 常量字段 webConsoleOn;release 下 onConsole 回调 仅一次字段读取即 return,不格式化、不写 hilog;setWebDebuggingAccess 本就仅 debug。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
5462643ce2
commit
eccd0efb91
@@ -39,6 +39,8 @@ export struct BridgeGameContainer {
|
||||
@State private sharePanelVisible: boolean = false;
|
||||
/** 当前分享面板的一次性回投事件名(用户选定平台后 emit 回 ShareProvider)。 */
|
||||
private shareResultEvent: string = '';
|
||||
/** H5 console 转发开关(构造期固化为编译期 DEBUG 常量;release 下 onConsole 仅一次字段读取即返回,零日志开销)。 */
|
||||
private readonly webConsoleOn: boolean = AppEnv.isDebug();
|
||||
|
||||
aboutToAppear(): void {
|
||||
if (AppEnv.isDebug()) {
|
||||
@@ -205,7 +207,7 @@ export struct BridgeGameContainer {
|
||||
|
||||
/** 转发 H5 console 到 hilog(debug 限定,带角色/级别/来源行,便于排查 H5 报错)。tag=WebConsole。 */
|
||||
private logWebConsole(role: string, event: OnConsoleEvent): void {
|
||||
if (!AppEnv.isDebug()) {
|
||||
if (!this.webConsoleOn) {
|
||||
return;
|
||||
}
|
||||
const m: ConsoleMessage = event.message;
|
||||
|
||||
@@ -24,6 +24,8 @@ export struct GenericWebContainer {
|
||||
private loaded: boolean = false;
|
||||
private exitDialog: boolean = false;
|
||||
private backToH5: boolean = false;
|
||||
/** H5 console 转发开关(构造期固化 DEBUG;release 下 onConsole 仅字段读取即返回)。 */
|
||||
private readonly webConsoleOn: boolean = AppEnv.isDebug();
|
||||
|
||||
aboutToAppear(): void {
|
||||
// settings 6 方法委托容器能力(§11.3)
|
||||
@@ -93,8 +95,8 @@ export struct GenericWebContainer {
|
||||
}
|
||||
})
|
||||
.onConsole((event: OnConsoleEvent) => {
|
||||
// 转发 H5 console 到 hilog(debug 限定,tag=WebConsole)
|
||||
if (AppEnv.isDebug()) {
|
||||
// 转发 H5 console 到 hilog(debug 限定,tag=WebConsole);release 仅字段读取即返回
|
||||
if (this.webConsoleOn) {
|
||||
const m: ConsoleMessage = event.message;
|
||||
Logger.tag('WebConsole').i(`[genericweb][lv${m.getMessageLevel()}] ${m.getMessage()} @${m.getSourceId()}:${m.getLineNumber()}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user