forked from openiap/opencore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogger.ts
More file actions
59 lines (58 loc) · 2.04 KB
/
Copy pathLogger.ts
File metadata and controls
59 lines (58 loc) · 2.04 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import * as winston from "winston";
import { Config } from "./Config";
import { LicenseFile, otel } from "./otelspec";
const path = require('path');
export class Logger {
public static otel: otel;
public static License: LicenseFile;
static configure(): winston.Logger {
const filename = path.join(Config.logpath, "openflow.log");
const options: any = {
file: {
level: "debug",
filename: filename,
handleExceptions: false,
json: true,
maxsize: 5242880, // 5MB
maxFiles: 5,
colorize: false,
},
console: {
level: "debug",
handleExceptions: false,
json: false,
colorize: true
},
};
const myFormat = winston.format.printf(info => {
if (info instanceof Error || info.stack) {
return `${info.timestamp} [${info.level}] ${info.message} \n ${info.stack}`;
}
return `${info.timestamp} [${info.level}] ${info.message}`;
});
options.console.format = winston.format.combine(
winston.format.errors({ stack: true }),
winston.format.timestamp({ format: 'HH:mm:ss.sss' }),
winston.format.colorize(),
winston.format.json(),
myFormat
);
const logger: winston.Logger = winston.createLogger({
level: "debug",
//format: winston.format.json(),
format: winston.format.combine(
winston.format.errors({ stack: true }),
winston.format.timestamp({ format: 'HH:mm:ss.sss' }),
winston.format.json(),
myFormat
),
transports: [
new winston.transports.File(options.file),
new winston.transports.Console(options.console)
]
});
Logger.instanse = logger;
return logger;
}
static instanse: winston.Logger = null;
}