19b256929Sopenharmony_ci/* 29b256929Sopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 39b256929Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 49b256929Sopenharmony_ci * you may not use this file except in compliance with the License. 59b256929Sopenharmony_ci * You may obtain a copy of the License at 69b256929Sopenharmony_ci * 79b256929Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 89b256929Sopenharmony_ci * 99b256929Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 109b256929Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 119b256929Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 129b256929Sopenharmony_ci * See the License for the specific language governing permissions and 139b256929Sopenharmony_ci * limitations under the License. 149b256929Sopenharmony_ci */ 159b256929Sopenharmony_ciimport hiLog from '@ohos.hilog'; 169b256929Sopenharmony_ci 179b256929Sopenharmony_ciconst DOMAIN: number = 0x002A; 189b256929Sopenharmony_ciconst TAG = "ScreenLock_Default"; 199b256929Sopenharmony_ciconst SYMBOL = " --> "; 209b256929Sopenharmony_ciconst FILTER_KEYS = [ 219b256929Sopenharmony_ci new RegExp('hide', "gi") 229b256929Sopenharmony_ci] 239b256929Sopenharmony_ci 249b256929Sopenharmony_ciexport function filterKey(target: any, propKey: string, descriptor: PropertyDescriptor) { 259b256929Sopenharmony_ci const original = descriptor.value; 269b256929Sopenharmony_ci descriptor.value = function (...args: string[]) { 279b256929Sopenharmony_ci let filterResult = args.map((str) => { 289b256929Sopenharmony_ci let tempStr = str 299b256929Sopenharmony_ci FILTER_KEYS.forEach((filterKey) => tempStr = tempStr.replace(filterKey, "**")) 309b256929Sopenharmony_ci return tempStr 319b256929Sopenharmony_ci }); 329b256929Sopenharmony_ci const result = original.call(this, ...filterResult); 339b256929Sopenharmony_ci return result; 349b256929Sopenharmony_ci }; 359b256929Sopenharmony_ci} 369b256929Sopenharmony_ci 379b256929Sopenharmony_ci/** 389b256929Sopenharmony_ci * Basic log class 399b256929Sopenharmony_ci */ 409b256929Sopenharmony_ciexport class Log { 419b256929Sopenharmony_ci /** 429b256929Sopenharmony_ci * Outputs debug-level logs. 439b256929Sopenharmony_ci * 449b256929Sopenharmony_ci * @param tag Identifies the log tag. 459b256929Sopenharmony_ci * @param format Indicates the log format string. 469b256929Sopenharmony_ci * @param args Indicates the log parameters. 479b256929Sopenharmony_ci * @since 7 489b256929Sopenharmony_ci */ 499b256929Sopenharmony_ci static showDebug(tag: string, format: string, ...args: any[]) { 509b256929Sopenharmony_ci if (Log.isLogGable(hiLog.LogLevel.DEBUG)) { 519b256929Sopenharmony_ci hiLog.debug(DOMAIN, TAG, tag + SYMBOL + format, args); 529b256929Sopenharmony_ci } 539b256929Sopenharmony_ci } 549b256929Sopenharmony_ci 559b256929Sopenharmony_ci /** 569b256929Sopenharmony_ci * Outputs info-level logs. 579b256929Sopenharmony_ci * 589b256929Sopenharmony_ci * @param tag Identifies the log tag. 599b256929Sopenharmony_ci * @param format Indicates the log format string. 609b256929Sopenharmony_ci * @param args Indicates the log parameters. 619b256929Sopenharmony_ci * @since 7 629b256929Sopenharmony_ci */ 639b256929Sopenharmony_ci static showInfo(tag: string, format: string, ...args: any[]) { 649b256929Sopenharmony_ci if (Log.isLogGable(hiLog.LogLevel.INFO)) { 659b256929Sopenharmony_ci hiLog.info(DOMAIN, TAG, tag + SYMBOL + format, args); 669b256929Sopenharmony_ci } 679b256929Sopenharmony_ci } 689b256929Sopenharmony_ci 699b256929Sopenharmony_ci /** 709b256929Sopenharmony_ci * Outputs warning-level logs. 719b256929Sopenharmony_ci * 729b256929Sopenharmony_ci * @param tag Identifies the log tag. 739b256929Sopenharmony_ci * @param format Indicates the log format string. 749b256929Sopenharmony_ci * @param args Indicates the log parameters. 759b256929Sopenharmony_ci * @since 7 769b256929Sopenharmony_ci */ 779b256929Sopenharmony_ci static showWarn(tag: string, format: string, ...args: any[]) { 789b256929Sopenharmony_ci if (Log.isLogGable(hiLog.LogLevel.WARN)) { 799b256929Sopenharmony_ci hiLog.warn(DOMAIN, TAG, tag + SYMBOL + format, args); 809b256929Sopenharmony_ci } 819b256929Sopenharmony_ci } 829b256929Sopenharmony_ci 839b256929Sopenharmony_ci /** 849b256929Sopenharmony_ci * Outputs error-level logs. 859b256929Sopenharmony_ci * 869b256929Sopenharmony_ci * @param tag Identifies the log tag. 879b256929Sopenharmony_ci * @param format Indicates the log format string. 889b256929Sopenharmony_ci * @param args Indicates the log parameters. 899b256929Sopenharmony_ci * @since 7 909b256929Sopenharmony_ci */ 919b256929Sopenharmony_ci static showError(tag: string, format: string, ...args: any[]) { 929b256929Sopenharmony_ci if (Log.isLogGable(hiLog.LogLevel.ERROR)) { 939b256929Sopenharmony_ci hiLog.error(DOMAIN, TAG, tag + SYMBOL + format, args); 949b256929Sopenharmony_ci } 959b256929Sopenharmony_ci } 969b256929Sopenharmony_ci 979b256929Sopenharmony_ci /** 989b256929Sopenharmony_ci * Outputs fatal-level logs. 999b256929Sopenharmony_ci * 1009b256929Sopenharmony_ci * @param tag Identifies the log tag. 1019b256929Sopenharmony_ci * @param format Indicates the log format string. 1029b256929Sopenharmony_ci * @param args Indicates the log parameters. 1039b256929Sopenharmony_ci * @since 7 1049b256929Sopenharmony_ci */ 1059b256929Sopenharmony_ci static showFatal(tag: string, format: string, ...args: any[]) { 1069b256929Sopenharmony_ci if (Log.isLogGable(hiLog.LogLevel.FATAL)) { 1079b256929Sopenharmony_ci hiLog.fatal(DOMAIN, TAG, tag + SYMBOL + format, args); 1089b256929Sopenharmony_ci } 1099b256929Sopenharmony_ci } 1109b256929Sopenharmony_ci 1119b256929Sopenharmony_ci /** 1129b256929Sopenharmony_ci * Checks whether logs of the specified tag, and level can be printed. 1139b256929Sopenharmony_ci * 1149b256929Sopenharmony_ci * @param tag Identifies the log tag. 1159b256929Sopenharmony_ci * @param level log level 1169b256929Sopenharmony_ci * @since 7 1179b256929Sopenharmony_ci */ 1189b256929Sopenharmony_ci private static isLogGable(level: hiLog.LogLevel): boolean { 1199b256929Sopenharmony_ci return hiLog.isLoggable(DOMAIN, TAG, level); 1209b256929Sopenharmony_ci } 1219b256929Sopenharmony_ci} 122