Mirror of https://github.com/roostorg/coop
github.com/roostorg/coop
1/* eslint-disable no-console */
2import { jsonStringify } from './encoding.js';
3
4// These helpers are only intended to be used when a SafeTracer is not available, e.g. during app startup before it has been initialized
5
6export function logErrorJson(m: { error: unknown; message?: string }) {
7 // Serialize error objects properly since they don't have enumerable properties
8 const serialized = {
9 ...m,
10 error: m.error instanceof Error
11 ? {
12 name: m.error.name,
13 message: m.error.message,
14 stack: m.error.stack,
15 ...(m.error as unknown as Record<string, unknown>)
16 }
17 : m.error
18 };
19 console.error(jsonStringify(serialized));
20}
21
22export function logJson(message: string) {
23 console.log(jsonStringify({ message }));
24}