From 9594c780eaccc13a53992b117fc048b14fa17e09 Mon Sep 17 00:00:00 2001 From: Chris Watts Date: Sat, 30 Sep 2017 11:41:16 -0700 Subject: [PATCH 1/2] Add corect timestamp to logging in non production environments --- lib/runtime/logger.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/runtime/logger.ts b/lib/runtime/logger.ts index 78987fbc..8498a456 100644 --- a/lib/runtime/logger.ts +++ b/lib/runtime/logger.ts @@ -3,7 +3,10 @@ import { padStart } from 'lodash'; import * as chalk from 'chalk'; +import * as moment from 'moment'; import DenaliObject from '../metal/object'; +import inject from '../metal/inject'; +import ConfigService from './config'; export type LogLevel = 'info' | 'warn' | 'error'; @@ -15,6 +18,7 @@ export type LogLevel = 'info' | 'warn' | 'error'; * @since 0.1.0 */ export default class Logger extends DenaliObject { + config = inject('service:config'); /** * Default log level if none specified. @@ -82,7 +86,17 @@ export default class Logger extends DenaliObject { if (this.levels.indexOf(level) === -1) { level = this.loglevel; } - let timestamp = (new Date()).toISOString(); + + let timestamp; + + if (this.config.environment !== 'production') { + // Prints Local time in ISO8601 format with fractional seconds. + timestamp = moment().format('YYYY-MM-DDTHH:mm:ss.SSSZ'); + } else { + // Prints UTC timestamp + timestamp = moment().toISOString(); + } + let padLength = this.levels.reduce((n: number, label) => Math.max(n, label.length), null); let levelLabel = padStart(level.toUpperCase(), padLength); if (this.colorize) { @@ -91,7 +105,7 @@ export default class Logger extends DenaliObject { levelLabel = colorizer(levelLabel); } /* tslint:disable:no-console */ - console.log(`[${ timestamp }] ${ levelLabel } - ${ msg }`); + console.log(`[${timestamp}] ${levelLabel} - ${msg}`); /* tslint:enable:no-console */ } From 5490ce3b590b58292d50dc1560d13971b0f080ee Mon Sep 17 00:00:00 2001 From: Ilya Radchenko Date: Sun, 20 Jan 2019 15:18:26 -0500 Subject: [PATCH 2/2] fix(logger): add back debugger if error --- lib/runtime/logger.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/runtime/logger.ts b/lib/runtime/logger.ts index 86a0e1d5..bcbbe0b2 100644 --- a/lib/runtime/logger.ts +++ b/lib/runtime/logger.ts @@ -121,6 +121,9 @@ export default class Logger extends DenaliObject { /* tslint:enable:no-console no-debugger*/ console.log(parts.join(' ')); + if (level === 'error') { + debugger; + } /* tslint:disable:no-console no-debugger */ }