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
60 lines (56 loc) · 1.82 KB
/
Copy pathLogger.ts
File metadata and controls
60 lines (56 loc) · 1.82 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
60
import * as winston from "winston";
import { Config } from "./Config";
const path = require('path');
export class Logger {
static configure(): winston.Logger {
var filename = path.join(Config.logpath, "openflow.log");
var 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 enumerateErrorFormat = winston.format(info => {
if ((info.message as any) instanceof Error) {
var e = (info.message as any) as Error;
info.message = Object.assign({
message: e.message,
stack: e.stack
}, info.message);
}
if (info instanceof Error) {
return Object.assign({
message: info.message,
stack: info.stack
}, info);
}
return info;
});
const logger: winston.Logger = winston.createLogger({
level: "debug",
//format: winston.format.json(),
format: winston.format.combine(
enumerateErrorFormat(),
winston.format.json()
),
transports: [
new winston.transports.File(options.file),
new winston.transports.Console(options.console)
]
});
Logger.instanse = logger;
return logger;
}
static instanse: winston.Logger = null;
}