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 */ 15import hilog from '@ohos.hilog' 16 17export class LogUtil { 18 private static readonly IS_DEBUG_ON: boolean = false; 19 private static readonly CONTACTS_DOMAIN: number = 0x0927; 20 private static readonly SLASH: string = "/"; 21 private static readonly COLON: string = ": "; 22 constructor() { 23 } 24 25 private static prefix(tag: string) { 26 return this.SLASH + tag + this.COLON; 27 } 28 29 static debug(tag: string, msg: string, ...args: any[]) { 30 if (this.IS_DEBUG_ON) { 31 hilog.info(this.CONTACTS_DOMAIN, this.prefix(tag), msg, args); 32 } else { 33 hilog.debug(this.CONTACTS_DOMAIN, this.prefix(tag), msg, args); 34 } 35 } 36 37 static info(tag: string, msg: string, ...args: any[]) { 38 hilog.info(this.CONTACTS_DOMAIN, this.prefix(tag), msg, args); 39 } 40 41 static warn(tag: string, msg: string, ...args: any[]) { 42 hilog.warn(this.CONTACTS_DOMAIN, this.prefix(tag), msg, args); 43 } 44 45 static error(tag: string, msg: string, ...args: any[]) { 46 hilog.error(this.CONTACTS_DOMAIN, this.prefix(tag), msg, args); 47 } 48}