1e75ebbc8Sopenharmony_ci// @ts-nocheck 2e75ebbc8Sopenharmony_ci/* 3e75ebbc8Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 4e75ebbc8Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 5e75ebbc8Sopenharmony_ci * you may not use this file except in compliance with the License. 6e75ebbc8Sopenharmony_ci * You may obtain a copy of the License at 7e75ebbc8Sopenharmony_ci * 8e75ebbc8Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 9e75ebbc8Sopenharmony_ci * 10e75ebbc8Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 11e75ebbc8Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 12e75ebbc8Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13e75ebbc8Sopenharmony_ci * See the License for the specific language governing permissions and 14e75ebbc8Sopenharmony_ci * limitations under the License. 15e75ebbc8Sopenharmony_ci */ 16e75ebbc8Sopenharmony_ci 17e75ebbc8Sopenharmony_ciimport Log from "./Log"; 18e75ebbc8Sopenharmony_ciimport hiSysEvent from '@ohos.hiSysEvent' 19e75ebbc8Sopenharmony_ci 20e75ebbc8Sopenharmony_ciconst TAG = 'SystemFaultLogger'; 21e75ebbc8Sopenharmony_ciconst APP_DOMAIN: string = "SYSTEMUI_APP"; 22e75ebbc8Sopenharmony_ciconst APP_LOG_NAME: string = "SYSTEMUI_FAULT"; 23e75ebbc8Sopenharmony_ciexport enum FaultID { 24e75ebbc8Sopenharmony_ci META_DIAGRAM_JUMP = "META_DIAGRAM_JUMP", 25e75ebbc8Sopenharmony_ci WORKER_ERROR = "WORKER_ABNORMAL_OCCURRENCE", 26e75ebbc8Sopenharmony_ci NOTIFICATION_ADD = "FAILED_NOTIFICATION_ADD" 27e75ebbc8Sopenharmony_ci} 28e75ebbc8Sopenharmony_ci 29e75ebbc8Sopenharmony_ciexport function writeFaultLog(logParam: object) { 30e75ebbc8Sopenharmony_ci const sysEventInfo = { 31e75ebbc8Sopenharmony_ci domain: APP_DOMAIN, 32e75ebbc8Sopenharmony_ci name: APP_LOG_NAME, 33e75ebbc8Sopenharmony_ci eventType: hiSysEvent.EventType.FAULT, 34e75ebbc8Sopenharmony_ci params: logParam 35e75ebbc8Sopenharmony_ci } 36e75ebbc8Sopenharmony_ci Log.showDebug(TAG, "fault log params is : " + JSON.stringify(sysEventInfo)) 37e75ebbc8Sopenharmony_ci hiSysEvent.write(sysEventInfo, (err, val) => { 38e75ebbc8Sopenharmony_ci Log.showDebug(TAG, "fault log params is : " + JSON.stringify(sysEventInfo)) 39e75ebbc8Sopenharmony_ci Log.showInfo(TAG, `write fault log result: ${val}`) 40e75ebbc8Sopenharmony_ci }) 41e75ebbc8Sopenharmony_ci} 42e75ebbc8Sopenharmony_ci 43e75ebbc8Sopenharmony_ciexport function SysFaultLogger(logParam: object) { 44e75ebbc8Sopenharmony_ci return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) { 45e75ebbc8Sopenharmony_ci const originalFunc = descriptor.value; 46e75ebbc8Sopenharmony_ci descriptor.value = function(...args) { 47e75ebbc8Sopenharmony_ci try { 48e75ebbc8Sopenharmony_ci originalFunc.apply(this, args); 49e75ebbc8Sopenharmony_ci } catch (err: any) { 50e75ebbc8Sopenharmony_ci Log.showInfo(TAG, "catch error in execute: " + propertyKey); 51e75ebbc8Sopenharmony_ci writeFaultLog(logParam); 52e75ebbc8Sopenharmony_ci } 53e75ebbc8Sopenharmony_ci }; 54e75ebbc8Sopenharmony_ci }; 55e75ebbc8Sopenharmony_ci}