diff options
author | Florian Dold <florian.dold@gmail.com> | 2016-11-19 16:33:29 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2016-11-19 16:33:29 +0100 |
commit | 2cd4a85ed4c57a705e3aeb88052be616e0461187 (patch) | |
tree | 7adf45ccda4eace9d350cb593ae19cd1151d300e /src/logging.ts | |
parent | 50090b5fb44f9d3986064dfe9b6190b66cbe49bf (diff) |
better error reporting
Diffstat (limited to 'src/logging.ts')
-rw-r--r-- | src/logging.ts | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/src/logging.ts b/src/logging.ts index ff0987396..788a7df55 100644 --- a/src/logging.ts +++ b/src/logging.ts @@ -42,7 +42,7 @@ function makeDebug() { export async function log(msg: string, level: Level = "info"): Promise<void> { let ci = getCallInfo(2); - return record(level, msg, ci.file, ci.line, ci.column); + return record(level, msg, undefined, ci.file, ci.line, ci.column); } function getCallInfo(level: number) { @@ -113,9 +113,10 @@ export interface LogEntry { timestamp: number; level: string; msg: string; - source: string|undefined; - col: number|undefined; - line: number|undefined; + detail?: string; + source?: string; + col?: number; + line?: number; id?: number; } @@ -133,7 +134,25 @@ export async function getLogs(): Promise<LogEntry[]> { */ let barrier: any; -export async function record(level: Level, msg: string, source?: string, line?: number, col?: number): Promise<void> { +export async function recordException(msg: string, e: any): Promise<void> { + let stack: string|undefined; + let frame: Frame|undefined; + try { + stack = e.stack; + if (stack) { + let lines = stack.split("\n"); + frame = parseStackLine(lines[1]); + } + } catch (e) { + // ignore + } + if (!frame) { + frame = unknownFrame; + } + return record("error", e.toString(), stack, frame.file, frame.line, frame.column); +} + +export async function record(level: Level, msg: string, detail?: string, source?: string, line?: number, col?: number): Promise<void> { if (typeof indexedDB === "undefined") { return; } @@ -166,6 +185,7 @@ export async function record(level: Level, msg: string, source?: string, line?: source, line, col, + detail, }; await new QueryRoot(db).put(logsStore, entry); } finally { |