logs correctly parse error.

This commit is contained in:
Miroslav Šedivý 2021-09-12 17:00:11 +02:00
parent b2f92a86bb
commit 94a62e4846
2 changed files with 16 additions and 2 deletions

View File

@ -28,9 +28,17 @@ export class NekoLogger extends Logger {
protected _send(level: string, message: string, fields?: Record<string, any>) { protected _send(level: string, message: string, fields?: Record<string, any>) {
if (!fields) { if (!fields) {
fields = { scope: this._scope } fields = { submodule: this._scope }
} else { } 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 const payload = { level, message, fields } as message.SystemLog

View File

@ -11,6 +11,12 @@ export class Logger {
let t = '' let t = ''
const args = [] const args = []
for (const name in fields) { 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) { if (typeof fields[name] === 'string' || fields[name] instanceof String) {
t += ' %c%s=%c"%s"' t += ' %c%s=%c"%s"'
} else { } else {