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