|
|
@ -82,36 +82,36 @@ 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); |
|
|
|
|
|
|
|
let clevel = level.padEnd(5); |
|
|
|
switch (level) { |
|
|
|
case 'debug': |
|
|
|
clevel = color.black(clevel); |
|
|
|
break; |
|
|
|
case 'info': |
|
|
|
clevel = color.green(clevel); |
|
|
|
break; |
|
|
|
case 'warn': |
|
|
|
clevel = color.yellow(clevel); |
|
|
|
break; |
|
|
|
case 'alert': |
|
|
|
clevel = color.red(clevel); |
|
|
|
break; |
|
|
|
case 'error': |
|
|
|
clevel = color.bgRed.white(clevel); |
|
|
|
break; |
|
|
|
case 'crit': |
|
|
|
clevel = color.bgRed.yellow(clevel); |
|
|
|
break; |
|
|
|
case 'fatal': |
|
|
|
clevel = color.bgRed.black(clevel); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
if (process.env.DTP_LOG_CONSOLE === 'enabled') { |
|
|
|
let clevel = level.padEnd(5); |
|
|
|
switch (level) { |
|
|
|
case 'debug': |
|
|
|
clevel = color.black(clevel); |
|
|
|
break; |
|
|
|
case 'info': |
|
|
|
clevel = color.green(clevel); |
|
|
|
break; |
|
|
|
case 'warn': |
|
|
|
clevel = color.yellow(clevel); |
|
|
|
break; |
|
|
|
case 'alert': |
|
|
|
clevel = color.red(clevel); |
|
|
|
break; |
|
|
|
case 'error': |
|
|
|
clevel = color.bgRed.white(clevel); |
|
|
|
break; |
|
|
|
case 'crit': |
|
|
|
clevel = color.bgRed.yellow(clevel); |
|
|
|
break; |
|
|
|
case 'fatal': |
|
|
|
clevel = color.bgRed.black(clevel); |
|
|
|
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 (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')) { |
|
|
|
await LogModel.create({ created: NOW, level, component: this.component, message, metadata }); |
|
|
|
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')) { |
|
|
|