diff --git a/src/index.ts b/src/index.ts index 0a7e1a1..ee23d86 100644 --- a/src/index.ts +++ b/src/index.ts @@ -149,7 +149,8 @@ export class Logestic { this.log(msg); }) .onError({ as: 'global' }, ({ request, error, code }) => { - const msg = formatAttr.onFailure({ request, error, code }); + let datetime = new Date(); + const msg = formatAttr.onFailure({ request, error, code, datetime }); this.log(msg); }); } diff --git a/src/presets/common.ts b/src/presets/common.ts index 34bbe14..bd01e0c 100644 --- a/src/presets/common.ts +++ b/src/presets/common.ts @@ -4,8 +4,8 @@ import chalk from 'chalk'; const preset: PresetValue = { uses: ['time', 'method', 'path', 'status'], formatAttr: { - onSuccess: ({ time, method, path, status }) => { - const grayTime = chalk.gray(`[${time!!.toISOString()}]`); + onSuccess({ time, method, path, status }) { + const grayTime = chalk.gray(`${time!!.toISOString()}`); const methodPath = chalk.cyan(`${method} ${path}`); let statusColor = chalk.white; @@ -15,7 +15,13 @@ const preset: PresetValue = { return `[${grayTime}] ${methodPath} ${statusColor(status)}`; }, - onFailure: () => '' + onFailure({ request, error, code, datetime }) { + const grayTime = chalk.gray(`${datetime.toISOString()}`); + const msg = chalk.red( + `Error: ${request.method} ${request.url} ${error.message} ${code}` + ); + return `[${grayTime}] ${msg}`; + } } }; diff --git a/src/types.ts b/src/types.ts index b773366..5df22a6 100644 --- a/src/types.ts +++ b/src/types.ts @@ -27,6 +27,7 @@ export type ErrorAttribute = { request: Request; error: Error; code: any; // either string description or number + datetime: Date; }; /**