-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.js
More file actions
34 lines (32 loc) · 820 Bytes
/
logger.js
File metadata and controls
34 lines (32 loc) · 820 Bytes
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
import { createLogger, format, transports } from "winston";
import * as util from "util";
function transform(info, opts) {
const args = info[Symbol.for("splat")];
if (args) {
info.message = util.format(info.message, ...args);
}
return info;
}
function utilFormatter() {
return { transform };
}
//log in a similar way to console.log
export const logger = createLogger({
level: "silly",
format: format.combine(
format.timestamp({ format: "YYYY-MM-DD HH:mm:ss.SSS" }),
utilFormatter(),
format.colorize(),
format.printf(
({ level, message, label, timestamp }) =>
`${timestamp} ${label || "-"} ${level}: ${message}`
)
),
transports: [
new transports.File({
filename: "test.log",
options: { flags: "w" },
}),
new transports.Console(),
],
});