From 94a62e484608579ccd6afae1f795fe9e6c34ceb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Sun, 12 Sep 2021 17:00:11 +0200 Subject: [PATCH] logs correctly parse error. --- src/component/internal/logger.ts | 12 ++++++++++-- src/component/utils/logger.ts | 6 ++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/component/internal/logger.ts b/src/component/internal/logger.ts index 5c655077..4346969f 100644 --- a/src/component/internal/logger.ts +++ b/src/component/internal/logger.ts @@ -28,9 +28,17 @@ export class NekoLogger extends Logger { protected _send(level: string, message: string, fields?: Record) { if (!fields) { - fields = { scope: this._scope } + fields = { submodule: this._scope } } else { - fields['scope'] = this._scope + fields['submodule'] = this._scope + } + + for (const key in fields) { + const field = fields[key] + + if (field instanceof Error) { + fields[key] = (field as Error).message + } } const payload = { level, message, fields } as message.SystemLog diff --git a/src/component/utils/logger.ts b/src/component/utils/logger.ts index 482d93fb..d1869d7a 100644 --- a/src/component/utils/logger.ts +++ b/src/component/utils/logger.ts @@ -11,6 +11,12 @@ export class Logger { let t = '' const args = [] for (const name in fields) { + if (fields[name] instanceof Error) { + t += ' %c%s="%s"%c' + args.push('color:#d84949;', name, (fields[name] as Error).message, '') + continue + } + if (typeof fields[name] === 'string' || fields[name] instanceof String) { t += ' %c%s=%c"%s"' } else {