2020-09-01 17:31:38 +00:00
|
|
|
import nodewindows from 'node-windows'
|
|
|
|
import bunyan from 'bunyan-lite'
|
|
|
|
import lowdb from './db.mjs'
|
|
|
|
|
|
|
|
export default function getLog(name) {
|
|
|
|
let settings
|
2020-09-07 00:47:53 +00:00
|
|
|
let ringbuffer = new bunyan.RingBuffer({ limit: 20 })
|
|
|
|
let ringbufferwarn = new bunyan.RingBuffer({ limit: 20 })
|
2020-09-01 17:31:38 +00:00
|
|
|
|
|
|
|
if (process.env.NODE_ENV === 'production') {
|
|
|
|
settings = {
|
|
|
|
"name": "service-core",
|
|
|
|
"streams": [{
|
|
|
|
path: 'log.log',
|
|
|
|
level: 'info',
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
settings = {
|
|
|
|
"name": "service-core",
|
|
|
|
"streams": [{
|
|
|
|
"stream": process.stdout,
|
|
|
|
"level": "debug"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let logger
|
|
|
|
|
|
|
|
settings.streams.push({
|
|
|
|
stream: ringbuffer,
|
|
|
|
type: 'raw',
|
|
|
|
level: 'info',
|
|
|
|
})
|
|
|
|
|
2020-09-07 00:47:53 +00:00
|
|
|
settings.streams.push({
|
|
|
|
stream: ringbufferwarn,
|
|
|
|
type: 'raw',
|
|
|
|
level: 'warn',
|
|
|
|
})
|
|
|
|
|
2020-09-01 17:31:38 +00:00
|
|
|
settings.streams.push({
|
|
|
|
stream: {
|
|
|
|
write: function(record) {
|
|
|
|
logger.emit('newlog', record)
|
|
|
|
},
|
|
|
|
end: function() {},
|
|
|
|
destroy: function() {},
|
|
|
|
destroySoon: function() {},
|
|
|
|
},
|
|
|
|
type: 'raw',
|
|
|
|
level: 'info',
|
|
|
|
})
|
|
|
|
|
|
|
|
// Create our logger.
|
|
|
|
logger = bunyan.createLogger(settings)
|
|
|
|
|
2020-09-07 00:47:53 +00:00
|
|
|
if (process.env.NODE_ENV === 'production') {
|
|
|
|
logger.event = new nodewindows.EventLogger(name)
|
|
|
|
} else {
|
|
|
|
logger.event = {
|
|
|
|
info: function() {},
|
|
|
|
warn: function() {},
|
|
|
|
error: function() {},
|
|
|
|
}
|
|
|
|
}
|
2020-09-01 17:31:38 +00:00
|
|
|
logger.ringbuffer = ringbuffer
|
2020-09-07 00:47:53 +00:00
|
|
|
logger.ringbufferwarn = ringbufferwarn
|
2020-09-01 17:31:38 +00:00
|
|
|
|
|
|
|
return logger
|
|
|
|
}
|