-
-
Notifications
You must be signed in to change notification settings - Fork 252
/
logger.js
34 lines (27 loc) · 869 Bytes
/
logger.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
/* eslint no-console: 0 */
import winston from 'winston'
import config from './config'
/**
* The logger. Logging to stdout
*/
// log function overwritten based on comments at https://github.com/winstonjs/winston/issues/1594#issuecomment-492420971
const LEVEL = Symbol.for('level')
const MESSAGE = Symbol.for('message')
const consoleTransport = new winston.transports.Console({
silent: config.unlockEnv === 'test',
log: function (info, callback) {
setImmediate(() => this.emit('logged', info))
if (this.stderrLevels[info[LEVEL]]) {
console.error(info[MESSAGE])
if (callback) callback()
return
}
console.log(info[MESSAGE])
if (callback) callback()
},
})
export default winston.createLogger({
format: winston.format.json(),
transports: [consoleTransport],
level: config.unlockEnv === 'dev' ? 'debug' : 'info',
})