1/**
2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import hiLog from '@ohos.hilog';
17import ExtensionAbility from '@ohos.app.ability.ExtensionAbility';
18
19const DOMAIN: number = 0x0500;
20const TAG = 'SettingsData';
21
22/**
23 *  升级到4.0.10 删除:
24 */
25export interface CommonEventData{
26  event: string;
27  bundleName?: string;
28  code?: number;
29  data?: string;
30  parameters?: { [key: string]: string | number | boolean | null | undefined };
31}
32
33/**
34 * Basic log class
35 */
36export class Log {
37  /**
38   * Outputs info-level logs.
39   *
40   * @param tag Identifies the log tag.
41   * @param format Indicates the log format string.
42   * @param args Indicates the log parameters.
43   * @since 7
44   */
45  static info(format: string, ...args: string[]): void {
46    if (Log.isLoggable(hiLog.LogLevel.INFO)) {
47      hiLog.info(DOMAIN, TAG, format, args);
48    }
49  }
50
51  /**
52   * Outputs debug-level logs.
53   *
54   * @param tag Identifies the log tag.
55   * @param format Indicates the log format string.
56   * @param args Indicates the log parameters.
57   * @since 7
58   */
59  static debug(format: string, ...args: string[]): void {
60    if (Log.isLoggable(hiLog.LogLevel.DEBUG)) {
61      hiLog.debug(DOMAIN, TAG, format, args);
62    }
63  }
64
65  /**
66   * Outputs warning-level logs.
67   *
68   * @param tag Identifies the log tag.
69   * @param format Indicates the log format string.
70   * @param args Indicates the log parameters.
71   * @since 7
72   */
73  static warn(format: string, ...args: string[]): void {
74    if (Log.isLoggable(hiLog.LogLevel.WARN)) {
75      hiLog.warn(DOMAIN, TAG, format, args);
76    }
77  }
78
79  /**
80   * Outputs error-level logs.
81   *
82   * @param tag Identifies the log tag.
83   * @param format Indicates the log format string.
84   * @param args Indicates the log parameters.
85   * @since 7
86   */
87  static error(format: string, ...args: string[]): void {
88    if (Log.isLoggable(hiLog.LogLevel.ERROR)) {
89      hiLog.error(DOMAIN, TAG, format, args);
90    }
91  }
92
93  /**
94   * Outputs fatal-level logs.
95   *
96   * @param tag Identifies the log tag.
97   * @param format Indicates the log format string.
98   * @param args Indicates the log parameters.
99   * @since 7
100   */
101  static fatal(format: string, ...args: string[]): void {
102    if (Log.isLoggable(hiLog.LogLevel.FATAL)) {
103      hiLog.fatal(DOMAIN, TAG, format, args);
104    }
105  }
106
107  /**
108   * Checks whether logs of the specified tag, and level can be printed.
109   *
110   * @param tag Identifies the log tag.
111   * @param level log level
112   * @since 7
113   */
114  private static isLoggable(level: hiLog.LogLevel): boolean {
115    return hiLog.isLoggable(DOMAIN, TAG, level);
116  }
117}
118