1/* 2 * Copyright (c) 2024 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'; 17 18/** 19 * 日志级别 20 */ 21const enum LogVersion { 22 Debug = 1, 23 Info = 2, 24 Warn = 3, 25 Error = 4, 26 Fatal = 5, 27} 28 29export class HiLog { 30 /** 31 * 日志级别, 注意在LogVersion声明之后 32 */ 33 public static readonly LOG_LEVEL = LogVersion.Debug; 34 35 /** 36 * TAG 37 */ 38 public static APP_TAG = 'DLPManager'; 39 40 /** 41 * Service Domain 42 */ 43 public static readonly LOG_DOMAIN = 0xf888; 44 45 /** 46 * 打印 Debug 日志 47 * @param tag 日志Tag 48 * @param message 打印信息 49 */ 50 public static debug(tag: string, message: string): void { 51 if (LogVersion.Debug >= HiLog.LOG_LEVEL) { 52 hilog.debug(HiLog.LOG_DOMAIN, `[${HiLog.APP_TAG}_${tag}]`, message); 53 } 54 } 55 56 /** 57 * 打印 Info 日志 58 * @param tag 日志Tag 59 * @param message 打印信息 60 */ 61 public static info(tag: string, message: string): void { 62 if (LogVersion.Info >= HiLog.LOG_LEVEL) { 63 hilog.info(HiLog.LOG_DOMAIN, `[${HiLog.APP_TAG}_${tag}]`, message); 64 } 65 } 66 67 /** 68 * 打印 Warn 日志 69 * @param tag 日志Tag 70 * @param message 打印信息 71 */ 72 public static warn(tag: string, message: string): void { 73 if (LogVersion.Warn >= HiLog.LOG_LEVEL) { 74 hilog.warn(HiLog.LOG_DOMAIN, `[${HiLog.APP_TAG}_${tag}]`, message); 75 } 76 } 77 78 /** 79 * 打印 Error 日志 80 * @param tag 日志Tag 81 * @param message 打印信息 82 */ 83 public static error(tag: string, message: string): void { 84 if (LogVersion.Error >= HiLog.LOG_LEVEL) { 85 hilog.error(HiLog.LOG_DOMAIN, `[${HiLog.APP_TAG}_${tag}]`, message); 86 } 87 } 88 89 /** 90 * 打印 Fatal 日志 91 * @param tag 日志Tag 92 * @param message 打印信息 93 */ 94 public static fatal(tag: string, message: string): void { 95 if (LogVersion.Fatal >= HiLog.LOG_LEVEL) { 96 hilog.fatal(HiLog.LOG_DOMAIN, `[${HiLog.APP_TAG}_${tag}]`, message); 97 } 98 } 99}