• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 level
18 */
19let LogLevel = {
20  /**
21     * debug
22     */
23  DEBUG: 3,
24
25  /**
26     * info
27     */
28  INFO: 4,
29
30  /**
31     * warn
32     */
33  WARN: 5,
34
35  /**
36     * error
37     */
38  ERROR: 6,
39
40  /**
41     * fatal
42     */
43  FATAL: 7,
44};
45
46const LOG_LEVEL = LogLevel.INFO
47
48/**
49 *  log package tool class
50 */
51export class LogUtil {
52  debug(msg): void {
53    if (LogLevel.DEBUG >= LOG_LEVEL) {
54      console.info(msg);
55    }
56  }
57
58  log(msg): void {
59    if (LogLevel.INFO >= LOG_LEVEL) {
60      console.log(msg);
61    }
62  }
63
64  info(msg): void {
65    if (LogLevel.INFO >= LOG_LEVEL) {
66      console.info(msg);
67    }
68  }
69
70  warn(msg): void {
71    if (LogLevel.WARN >= LOG_LEVEL) {
72      console.warn(msg);
73    }
74  }
75
76  error(msg): void {
77    if (LogLevel.ERROR >= LOG_LEVEL) {
78      console.error(msg);
79    }
80  }
81}
82
83let mLogUtil = new LogUtil();
84export default mLogUtil as LogUtil
85;
86