1e75ebbc8Sopenharmony_ci/*
2e75ebbc8Sopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3e75ebbc8Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4e75ebbc8Sopenharmony_ci * you may not use this file except in compliance with the License.
5e75ebbc8Sopenharmony_ci * You may obtain a copy of the License at
6e75ebbc8Sopenharmony_ci *
7e75ebbc8Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8e75ebbc8Sopenharmony_ci *
9e75ebbc8Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10e75ebbc8Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11e75ebbc8Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12e75ebbc8Sopenharmony_ci * See the License for the specific language governing permissions and
13e75ebbc8Sopenharmony_ci * limitations under the License.
14e75ebbc8Sopenharmony_ci */
15e75ebbc8Sopenharmony_ciimport HiLog from '@ohos.hilog';
16e75ebbc8Sopenharmony_ci
17e75ebbc8Sopenharmony_ciconst DOMAIN: number = 0x001A;
18e75ebbc8Sopenharmony_ciconst TAG = "SystemUI_Default";
19e75ebbc8Sopenharmony_ciconst SYMBOL = " --> ";
20e75ebbc8Sopenharmony_ciconst FILTER_KEYS = [
21e75ebbc8Sopenharmony_ci    new RegExp('hide', "gi")
22e75ebbc8Sopenharmony_ci]
23e75ebbc8Sopenharmony_ci
24e75ebbc8Sopenharmony_ciexport function filterKey(target: any, propKey: string, descriptor: PropertyDescriptor) {
25e75ebbc8Sopenharmony_ci    const original = descriptor.value;
26e75ebbc8Sopenharmony_ci    descriptor.value = function (...args: string[]) {
27e75ebbc8Sopenharmony_ci        let filterResult = args.map((str) => {
28e75ebbc8Sopenharmony_ci            let tempStr = str
29e75ebbc8Sopenharmony_ci            FILTER_KEYS.forEach((filterKey) => tempStr = tempStr.replace(filterKey, "**"))
30e75ebbc8Sopenharmony_ci            return tempStr
31e75ebbc8Sopenharmony_ci        });
32e75ebbc8Sopenharmony_ci        const result = original.call(this, ...filterResult);
33e75ebbc8Sopenharmony_ci        return result;
34e75ebbc8Sopenharmony_ci    };
35e75ebbc8Sopenharmony_ci}
36e75ebbc8Sopenharmony_ci
37e75ebbc8Sopenharmony_ci/**
38e75ebbc8Sopenharmony_ci * Basic log class
39e75ebbc8Sopenharmony_ci */
40e75ebbc8Sopenharmony_ciexport default class Log {
41e75ebbc8Sopenharmony_ci    /**
42e75ebbc8Sopenharmony_ci     * Outputs debug-level logs.
43e75ebbc8Sopenharmony_ci     *
44e75ebbc8Sopenharmony_ci     * @param tag Identifies the log tag.
45e75ebbc8Sopenharmony_ci     * @param format Indicates the log format string.
46e75ebbc8Sopenharmony_ci     * @param args Indicates the log parameters.
47e75ebbc8Sopenharmony_ci     * @since 7
48e75ebbc8Sopenharmony_ci     */
49e75ebbc8Sopenharmony_ci    static showDebug(tag: string, format: string, ...args: any[]) {
50e75ebbc8Sopenharmony_ci        if (Log.isLoggable(HiLog.LogLevel.DEBUG)) {
51e75ebbc8Sopenharmony_ci            HiLog.debug(DOMAIN, TAG, tag + SYMBOL + format, args);
52e75ebbc8Sopenharmony_ci        }
53e75ebbc8Sopenharmony_ci    }
54e75ebbc8Sopenharmony_ci
55e75ebbc8Sopenharmony_ci    /**
56e75ebbc8Sopenharmony_ci     * Outputs info-level logs.
57e75ebbc8Sopenharmony_ci     *
58e75ebbc8Sopenharmony_ci     * @param tag Identifies the log tag.
59e75ebbc8Sopenharmony_ci     * @param format Indicates the log format string.
60e75ebbc8Sopenharmony_ci     * @param args Indicates the log parameters.
61e75ebbc8Sopenharmony_ci     * @since 7
62e75ebbc8Sopenharmony_ci     */
63e75ebbc8Sopenharmony_ci    static showInfo(tag: string, format: string, ...args: any[]) {
64e75ebbc8Sopenharmony_ci        if (Log.isLoggable(HiLog.LogLevel.INFO)) {
65e75ebbc8Sopenharmony_ci            HiLog.info(DOMAIN, TAG, tag + SYMBOL + format, args);
66e75ebbc8Sopenharmony_ci        }
67e75ebbc8Sopenharmony_ci    }
68e75ebbc8Sopenharmony_ci
69e75ebbc8Sopenharmony_ci    /**
70e75ebbc8Sopenharmony_ci     * Outputs warning-level logs.
71e75ebbc8Sopenharmony_ci     *
72e75ebbc8Sopenharmony_ci     * @param tag Identifies the log tag.
73e75ebbc8Sopenharmony_ci     * @param format Indicates the log format string.
74e75ebbc8Sopenharmony_ci     * @param args Indicates the log parameters.
75e75ebbc8Sopenharmony_ci     * @since 7
76e75ebbc8Sopenharmony_ci     */
77e75ebbc8Sopenharmony_ci    static showWarn(tag: string, format: string, ...args: any[]) {
78e75ebbc8Sopenharmony_ci        if (Log.isLoggable(HiLog.LogLevel.WARN)) {
79e75ebbc8Sopenharmony_ci            HiLog.warn(DOMAIN, TAG, tag + SYMBOL + format, args);
80e75ebbc8Sopenharmony_ci        }
81e75ebbc8Sopenharmony_ci    }
82e75ebbc8Sopenharmony_ci
83e75ebbc8Sopenharmony_ci    /**
84e75ebbc8Sopenharmony_ci     * Outputs error-level logs.
85e75ebbc8Sopenharmony_ci     *
86e75ebbc8Sopenharmony_ci     * @param tag Identifies the log tag.
87e75ebbc8Sopenharmony_ci     * @param format Indicates the log format string.
88e75ebbc8Sopenharmony_ci     * @param args Indicates the log parameters.
89e75ebbc8Sopenharmony_ci     * @since 7
90e75ebbc8Sopenharmony_ci     */
91e75ebbc8Sopenharmony_ci    static showError(tag: string, format: string, ...args: any[]) {
92e75ebbc8Sopenharmony_ci        if (Log.isLoggable(HiLog.LogLevel.ERROR)) {
93e75ebbc8Sopenharmony_ci            HiLog.error(DOMAIN, TAG, tag + SYMBOL + format, args);
94e75ebbc8Sopenharmony_ci        }
95e75ebbc8Sopenharmony_ci    }
96e75ebbc8Sopenharmony_ci
97e75ebbc8Sopenharmony_ci    /**
98e75ebbc8Sopenharmony_ci     * Outputs fatal-level logs.
99e75ebbc8Sopenharmony_ci     *
100e75ebbc8Sopenharmony_ci     * @param tag Identifies the log tag.
101e75ebbc8Sopenharmony_ci     * @param format Indicates the log format string.
102e75ebbc8Sopenharmony_ci     * @param args Indicates the log parameters.
103e75ebbc8Sopenharmony_ci     * @since 7
104e75ebbc8Sopenharmony_ci     */
105e75ebbc8Sopenharmony_ci    static showFatal(tag: string, format: string, ...args: any[]) {
106e75ebbc8Sopenharmony_ci        if (Log.isLoggable(HiLog.LogLevel.FATAL)) {
107e75ebbc8Sopenharmony_ci            HiLog.fatal(DOMAIN, TAG, tag + SYMBOL + format, args);
108e75ebbc8Sopenharmony_ci        }
109e75ebbc8Sopenharmony_ci    }
110e75ebbc8Sopenharmony_ci
111e75ebbc8Sopenharmony_ci    /**
112e75ebbc8Sopenharmony_ci     * Checks whether logs of the specified tag, and level can be printed.
113e75ebbc8Sopenharmony_ci     *
114e75ebbc8Sopenharmony_ci     * @param tag Identifies the log tag.
115e75ebbc8Sopenharmony_ci     * @param level log level
116e75ebbc8Sopenharmony_ci     * @since 7
117e75ebbc8Sopenharmony_ci     */
118e75ebbc8Sopenharmony_ci    private static isLoggable(level: HiLog.LogLevel): boolean {
119e75ebbc8Sopenharmony_ci        return HiLog.isLoggable(DOMAIN, TAG, level);
120e75ebbc8Sopenharmony_ci    }
121e75ebbc8Sopenharmony_ci}
122