-
Notifications
You must be signed in to change notification settings - Fork 68
/
winston.js
46 lines (39 loc) · 1.34 KB
/
winston.js
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
35
36
37
38
39
40
41
42
43
44
45
46
const winston = require('winston');
const expressWinston = require('express-winston');
const config = require('./config');
const logger = winston.createLogger({
level: config.log.level,
format: winston.format.combine(winston.format.simple(), winston.format.colorize()),
defaultMeta: {
service: `pages-${config.app.appEnv}`,
},
transports: [new winston.transports.Console()],
silent: config.log.silent,
});
const databaseLogger = winston.createLogger({
level: 'warn',
format: winston.format.combine(winston.format.simple(), winston.format.colorize()),
defaultMeta: {
service: `pages-${config.app.appEnv}-database`,
},
transports: [new winston.transports.Console()],
silent: config.log.silent,
});
expressWinston.requestWhitelist.push('body');
expressWinston.bodyBlacklist.push('password', 'value');
const expressLogger = expressWinston.logger({
format: winston.format.combine(winston.format.simple(), winston.format.colorize()),
transports: [new winston.transports.Console()],
skip: () => config.log.silent,
});
const expressErrorLogger = expressWinston.errorLogger({
format: winston.format.combine(winston.format.json(), winston.format.colorize()),
transports: [new winston.transports.Console()],
skip: () => config.log.silent,
});
module.exports = {
logger,
expressLogger,
expressErrorLogger,
databaseLogger,
};