-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlogger.js
More file actions
34 lines (29 loc) · 787 Bytes
/
logger.js
File metadata and controls
34 lines (29 loc) · 787 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
'use strict';
const config = require('config');
const winston = require('winston');
const pjson = require('./package.json');
let winstonFormat = winston.format.json();
const metaData = {
app: pjson.name,
version: pjson.version,
time: new Date().toISOString(),
};
if (process.env.NODE_ENV !== 'production') {
winstonFormat = winston.format.combine(
winston.format.json(),
winston.format.prettyPrint(),
winston.format.colorize(),
);
}
const logger = winston.createLogger({
defaultMeta: metaData,
transports: [
new winston.transports.Console({
level: config.loggerLevel,
format: winstonFormat,
handleExceptions: true,
silent: process.env.NODE_ENV === 'test' && !process.env.SHOW_LOGS,
}),
],
});
module.exports = { logger };