-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.js
More file actions
33 lines (28 loc) · 929 Bytes
/
logger.js
File metadata and controls
33 lines (28 loc) · 929 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
/* eslint-disable import/no-extraneous-dependencies */
const winston = require("winston");
const config = require("config");
require("express-async-errors");
const uncaughtExceptionsLogFile = "uncaughtExceptions.log";
const logFile = "logfile.log";
const logFormat = winston.format.printf(
({ level, message, timestamp }) =>
`[${timestamp}] [${level}]] ${message}`
);
const logger = winston.createLogger({
level: config.get("log_level"),
format: winston.format.combine(
winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }),
logFormat
),
transports: [new winston.transports.File({ filename: logFile })],
exceptionHandlers: [
new winston.transports.File({ filename: uncaughtExceptionsLogFile }),
],
rejectionHandlers: [
new winston.transports.File({ filename: uncaughtExceptionsLogFile }),
],
});
process.on("unhandledRejection", (ex) => {
throw ex;
});
module.exports = logger;