16e80583aSopenharmony_ci/**
26e80583aSopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
36e80583aSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
46e80583aSopenharmony_ci * you may not use this file except in compliance with the License.
56e80583aSopenharmony_ci * You may obtain a copy of the License at
66e80583aSopenharmony_ci *
76e80583aSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
86e80583aSopenharmony_ci *
96e80583aSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
106e80583aSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
116e80583aSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
126e80583aSopenharmony_ci * See the License for the specific language governing permissions and
136e80583aSopenharmony_ci * limitations under the License.
146e80583aSopenharmony_ci */
156e80583aSopenharmony_ciimport hilog from '@ohos.hilog';
166e80583aSopenharmony_ci
176e80583aSopenharmony_ciconst DOMAIN: number = 0x001b;
186e80583aSopenharmony_ciconst TAG = "Launcher_Default";
196e80583aSopenharmony_ciconst SYMBOL = " --> ";
206e80583aSopenharmony_ci
216e80583aSopenharmony_ci/**
226e80583aSopenharmony_ci * Basic log class
236e80583aSopenharmony_ci */
246e80583aSopenharmony_ciexport class Log {
256e80583aSopenharmony_ci    /**
266e80583aSopenharmony_ci     * Outputs info-level logs.
276e80583aSopenharmony_ci     *
286e80583aSopenharmony_ci     * @param tag Identifies the log tag.
296e80583aSopenharmony_ci     * @param format Indicates the log format string.
306e80583aSopenharmony_ci     * @param args Indicates the log parameters.
316e80583aSopenharmony_ci     * @since 7
326e80583aSopenharmony_ci     */
336e80583aSopenharmony_ci    static showInfo(tag: string, format: string, ...args: any[]) {
346e80583aSopenharmony_ci        if (Log.isLoggable(tag, hilog.LogLevel.INFO)) {
356e80583aSopenharmony_ci            hilog.info(DOMAIN, TAG, tag + SYMBOL + format, args);
366e80583aSopenharmony_ci        }
376e80583aSopenharmony_ci    }
386e80583aSopenharmony_ci
396e80583aSopenharmony_ci    /**
406e80583aSopenharmony_ci    * Outputs debug-level logs.
416e80583aSopenharmony_ci    *
426e80583aSopenharmony_ci    * @param tag Identifies the log tag.
436e80583aSopenharmony_ci    * @param format Indicates the log format string.
446e80583aSopenharmony_ci    * @param args Indicates the log parameters.
456e80583aSopenharmony_ci    * @since 7
466e80583aSopenharmony_ci    */
476e80583aSopenharmony_ci    static showDebug(tag: string, format: string, ...args: any[]) {
486e80583aSopenharmony_ci        if (Log.isLoggable(tag, hilog.LogLevel.DEBUG)) {
496e80583aSopenharmony_ci            hilog.debug(DOMAIN, TAG, tag + SYMBOL + format, args);
506e80583aSopenharmony_ci        }
516e80583aSopenharmony_ci    }
526e80583aSopenharmony_ci
536e80583aSopenharmony_ci    /**
546e80583aSopenharmony_ci     * Outputs warning-level logs.
556e80583aSopenharmony_ci     *
566e80583aSopenharmony_ci     * @param tag Identifies the log tag.
576e80583aSopenharmony_ci     * @param format Indicates the log format string.
586e80583aSopenharmony_ci     * @param args Indicates the log parameters.
596e80583aSopenharmony_ci     * @since 7
606e80583aSopenharmony_ci     */
616e80583aSopenharmony_ci    static showWarn(tag: string, format: string, ...args: any[]) {
626e80583aSopenharmony_ci        if (Log.isLoggable(tag, hilog.LogLevel.WARN)) {
636e80583aSopenharmony_ci            hilog.warn(DOMAIN, TAG, tag + SYMBOL + format, args);
646e80583aSopenharmony_ci        }
656e80583aSopenharmony_ci    }
666e80583aSopenharmony_ci
676e80583aSopenharmony_ci    /**
686e80583aSopenharmony_ci     * Outputs error-level logs.
696e80583aSopenharmony_ci     *
706e80583aSopenharmony_ci     * @param tag Identifies the log tag.
716e80583aSopenharmony_ci     * @param format Indicates the log format string.
726e80583aSopenharmony_ci     * @param args Indicates the log parameters.
736e80583aSopenharmony_ci     * @since 7
746e80583aSopenharmony_ci     */
756e80583aSopenharmony_ci    static showError(tag: string, format: string, ...args: any[]) {
766e80583aSopenharmony_ci        if (Log.isLoggable(tag, hilog.LogLevel.ERROR)) {
776e80583aSopenharmony_ci            hilog.error(DOMAIN, TAG, tag + SYMBOL + format, args);
786e80583aSopenharmony_ci        }
796e80583aSopenharmony_ci    }
806e80583aSopenharmony_ci
816e80583aSopenharmony_ci    /**
826e80583aSopenharmony_ci     * Outputs fatal-level logs.
836e80583aSopenharmony_ci     *
846e80583aSopenharmony_ci     * @param tag Identifies the log tag.
856e80583aSopenharmony_ci     * @param format Indicates the log format string.
866e80583aSopenharmony_ci     * @param args Indicates the log parameters.
876e80583aSopenharmony_ci     * @since 7
886e80583aSopenharmony_ci     */
896e80583aSopenharmony_ci    static showFatal(tag: string, format: string, ...args: any[]) {
906e80583aSopenharmony_ci        if (Log.isLoggable(tag, hilog.LogLevel.FATAL)) {
916e80583aSopenharmony_ci            hilog.fatal(DOMAIN, TAG, tag + SYMBOL + format, args);
926e80583aSopenharmony_ci        }
936e80583aSopenharmony_ci    }
946e80583aSopenharmony_ci
956e80583aSopenharmony_ci    /**
966e80583aSopenharmony_ci     * Checks whether logs of the specified tag, and level can be printed.
976e80583aSopenharmony_ci     *
986e80583aSopenharmony_ci     * @param tag Identifies the log tag.
996e80583aSopenharmony_ci     * @param level log level
1006e80583aSopenharmony_ci     * @since 7
1016e80583aSopenharmony_ci     */
1026e80583aSopenharmony_ci    private static isLoggable(tag:string, level: hilog.LogLevel): boolean {
1036e80583aSopenharmony_ci        return hilog.isLoggable(DOMAIN, tag, level);
1046e80583aSopenharmony_ci    }
1056e80583aSopenharmony_ci}
106