|
|
@ -82,8 +82,10 @@ class SiteLog { |
|
|
|
|
|
|
|
async writeLog (level, message, metadata) { |
|
|
|
const NOW = new Date(); |
|
|
|
const ctimestamp = color.black(moment(NOW).format('YYYY-MM-DD HH:mm:ss.SSS')); |
|
|
|
const ccomponentSlug = color.cyan(this.component.slug); |
|
|
|
const cmessage = color.darkGray(message); |
|
|
|
|
|
|
|
if (process.env.DTP_LOG_CONSOLE === 'enabled') { |
|
|
|
let clevel = level.padEnd(5); |
|
|
|
switch (level) { |
|
|
|
case 'debug': |
|
|
@ -109,9 +111,7 @@ class SiteLog { |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
const ctimestamp = color.black(moment(NOW).format('YYYY-MM-DD HH:mm:ss.SSS')); |
|
|
|
const ccomponentSlug = color.cyan(this.component.slug); |
|
|
|
const cmessage = color.darkGray(message); |
|
|
|
if (process.env.DTP_LOG_CONSOLE === 'enabled') { |
|
|
|
if (metadata) { |
|
|
|
console.log(`${ctimestamp} ${clevel} ${ccomponentSlug} ${cmessage}`, util.inspect(metadata, false, Infinity, true)); |
|
|
|
} else { |
|
|
@ -120,7 +120,16 @@ class SiteLog { |
|
|
|
} |
|
|
|
|
|
|
|
if (LogModel && (process.env.DTP_LOG_MONGODB === 'enabled')) { |
|
|
|
try { |
|
|
|
await LogModel.create({ created: NOW, level, component: this.component, message, metadata }); |
|
|
|
} catch (error) { |
|
|
|
console.log( |
|
|
|
'failed to write log entry to MongoDB', |
|
|
|
`${ctimestamp} ${clevel} ${ccomponentSlug} ${cmessage}`, |
|
|
|
{ error }, |
|
|
|
); |
|
|
|
// fall through
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (LogStream && (process.env.DTP_LOG_FILE === 'enabled')) { |
|
|
|