-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogging.ts
38 lines (32 loc) · 902 Bytes
/
logging.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import winston from "winston";
export default class Logger {
private static loggerName = "logger";
private static logger: winston.Logger;
public static Init(): void {
Logger.logger = winston.loggers.add(Logger.loggerName, {
format: winston.format.combine(
winston.format.timestamp(),
winston.format.printf((i) => `[${i.level}] ${i.timestamp} - ${i.message}`),
),
transports: [
new winston.transports.Console(),
],
});
}
public static Info(msg: string): void {
Logger.loggerFunc("info", msg);
}
public static Warn(msg: string): void {
Logger.loggerFunc("warn", msg);
}
public static Error(msg: string): void {
Logger.loggerFunc("error", msg);
}
private static loggerFunc(lvl: string, msg: string) {
if (!Logger.logger) return;
Logger.logger.log({
level: lvl,
message: msg,
});
}
}