-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlog.js
More file actions
28 lines (24 loc) · 706 Bytes
/
log.js
File metadata and controls
28 lines (24 loc) · 706 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
const winston = require('winston');
const util = require('util');
const { createLogger, format, transports } = winston;
const fmt = format.combine(
format.splat(),
format.printf(({ level, message }) => util.format('%s %s', `[${level.toLocaleUpperCase()}]`.padEnd(7, ' '), message)),
);
/**
* @type {winston.Logger}
* @private
*/
const log = createLogger(process.env.NODE_ENV === 'production' ? {
format: fmt,
level: 'info',
transports: [
new transports.File({ filename: 'info.console', level: 'info' }),
new transports.Console({ level: 'warn' }),
],
} : {
format: fmt,
level: process.env.LOG_LVL || 'warn',
transports: [new transports.Console()],
});
module.exports = log;