Skip to content

Commit 01f02e7

Browse files
committed
Log queries in debugMode on web.
1 parent 58cf447 commit 01f02e7

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

packages/web/src/db/adapters/LockedAsyncDatabaseAdapter.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,30 @@ export class LockedAsyncDatabaseAdapter
6767
const start = performance.now();
6868
try {
6969
const r = await originalExecute(sql, bindings);
70+
const duration = performance.now() - start;
7071
performance.measure(`[SQL] ${sql}`, { start });
72+
console.log(
73+
'%c[SQL] %c%s %c%s',
74+
'color: grey; font-weight: normal',
75+
durationStyle(duration),
76+
`[${duration.toFixed(1)}ms]`,
77+
'color: grey; font-weight: normal',
78+
sql
79+
);
7180
return r;
7281
} catch (e: any) {
82+
const duration = performance.now() - start;
7383
performance.measure(`[SQL] [ERROR: ${e.message}] ${sql}`, { start });
84+
console.error(
85+
'%c[SQL] %c%s %c%s %c%s',
86+
'color: grey; font-weight: normal',
87+
'color: red; font-weight: normal',
88+
`[ERROR: ${e.message}]`,
89+
durationStyle(duration),
90+
`[${duration.toFixed(1)}ms]`,
91+
'color: grey; font-weight: normal',
92+
sql
93+
);
7494
throw e;
7595
}
7696
};
@@ -356,3 +376,13 @@ export class LockedAsyncDatabaseAdapter
356376
};
357377
};
358378
}
379+
380+
function durationStyle(duration: number) {
381+
if (duration < 30) {
382+
return 'color: grey; font-weight: normal';
383+
} else if (duration < 300) {
384+
return 'color: blue; font-weight: normal';
385+
} else {
386+
return 'color: red; font-weight: normal';
387+
}
388+
}

0 commit comments

Comments
 (0)