1/*
2 * Copyright (c) 2023-2024 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
16export interface LoggerInterface {
17  trace: (message: string) => void;
18  debug: (message: string) => void;
19  info: (message: string) => void;
20  warn: (message: string) => void;
21  error: (message: string) => void;
22}
23
24export class Logger {
25  static init(instance: LoggerInterface): void {
26    this.instance_ = instance;
27  }
28
29  static trace(message: string): void {
30    this.getInstance().trace(message);
31  }
32
33  static debug(message: string): void {
34    this.getInstance().debug(message);
35  }
36
37  static info(message: string): void {
38    this.getInstance().info(message);
39  }
40
41  static warn(message: string): void {
42    this.getInstance().warn(message);
43  }
44
45  static error(message: string): void {
46    this.getInstance().error(message);
47  }
48
49  private static getInstance(): LoggerInterface {
50    if (!this.instance_) {
51      throw new Error('Not initialized');
52    }
53    return this.instance_;
54  }
55
56  private static instance_?: LoggerInterface;
57}
58