-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogging.js
More file actions
27 lines (25 loc) · 747 Bytes
/
logging.js
File metadata and controls
27 lines (25 loc) · 747 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
const winston = require("winston");
const formatMeta = (meta) => {
const splat = meta[Symbol.for("splat")];
return splat && splat.length
? splat.length === 1
? typeof splat[0] === "object"
? JSON.stringify(splat[0], null, 2)
: splat[0]
: JSON.stringify(splat, null, 2)
: "";
};
module.exports = winston.createLogger({
level: "debug",
format: winston.format.combine(
winston.format.align(),
winston.format.colorize(),
winston.format.timestamp(),
winston.format.splat(),
winston.format.printf(
({ level, message, timestamp, ...metadata }) =>
`[${timestamp}] [${level}] ${message} ${formatMeta(metadata)}`
)
),
transports: [new winston.transports.Console()],
});