-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloggerToFile.js
More file actions
30 lines (27 loc) · 842 Bytes
/
loggerToFile.js
File metadata and controls
30 lines (27 loc) · 842 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
/*jshint esversion: 6 */
const winston = require('winston');
const fs = require('fs');
const logDir = 'log';
const env = process.env.NODE_ENV || 'development';
winston.level = process.env.LOG_LEVEL || 'info';
// 'error', 'warn', 'info', 'verbose', 'debug', 'silly'.
if (!fs.existsSync(logDir)) {
fs.mkdirSync(logDir);
}
const tsFormat = () => (new Date()).toLocaleTimeString();
const logger = new (winston.Logger)({
transports: [
// colorize the output to the console
new (winston.transports.Console)({
timestamp: tsFormat,
colorize: true,
level: 'info'
}),
new (winston.transports.File)({
filename: `${logDir}/results_${new Date().getMonth()}-${new Date().getDate()}.log`,
timestamp: tsFormat,
level: env === 'development' ? 'debug' : 'info'
})
]
});
module.exports = logger;