1/** 2 * Copyright (c) 2022 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 16/** 17 * Log Util 18 * 19 * standard : 20 * 1. define TAG, recommend class name。 21 * 2. switch IS_DEBUG_ON as true, when debugging. 22 * 3. msg should be short and valuable. 23 * 4. choose appropriate function. 24 * 5. the function execute many times can not print. 25 * 6. uniqueness. 26 */ 27import Log from "@ohos.hilog"; 28 29const TAG = "ContactLog"; 30const DOMAIN = 0x0900; 31 32export class HiLog { 33 34 private static readonly COLON: string = ": "; 35 36 constructor() { 37 } 38 39 private static prefix(tag: string) { 40 return tag + this.COLON; 41 } 42 43 static d(tag: string, msg: string, ...args: any[]) { 44 Log.debug(DOMAIN, TAG, this.prefix(tag) + msg, args); 45 } 46 47 static i(tag: string, msg: string, ...args: any[]) { 48 Log.info(DOMAIN, TAG, this.prefix(tag) + msg, args); 49 } 50 51 static w(tag: string, msg: string, ...args: any[]) { 52 Log.warn(DOMAIN, TAG, this.prefix(tag) + msg, args); 53 } 54 55 static e(tag: string, msg: string, ...args: any[]) { 56 Log.error(DOMAIN, TAG, this.prefix(tag) + msg, args); 57 } 58} 59 60