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