Browse Source

fix more of the logging & log display

pull/137/head
Trent Larson 1 week ago
parent
commit
01c33069c4
  1. 6
      src/db/databaseUtil.ts
  2. 21
      src/views/LogView.vue

6
src/db/databaseUtil.ts

@ -133,13 +133,13 @@ let lastCleanupDate: string | null = null;
export async function logToDb(message: string): Promise<void> {
const platform = PlatformServiceFactory.getInstance();
const todayKey = new Date().toDateString();
const fullMessage = `${new Date().toISOString()} ${message}`;
const nowKey = new Date().toISOString();
try {
// Try to insert first, if it fails due to UNIQUE constraint, update instead
await platform.dbExec("INSERT INTO logs (date, message) VALUES (?, ?)", [
todayKey,
fullMessage,
nowKey,
message,
]);
// Clean up old logs (keep only last 7 days) - do this less frequently

21
src/views/LogView.vue

@ -38,7 +38,7 @@
<div v-for="(log, index) in logs" :key="index" class="mb-2">
<pre
class="bg-slate-100 p-4 rounded-md overflow-x-auto whitespace-pre-wrap"
>{{ log.message }}</pre
>{{ log.date }} {{ log.message }}</pre
>
</div>
</div>
@ -81,21 +81,22 @@ export default class LogView extends Vue {
let allLogs: Log[] = [];
const platformService = PlatformServiceFactory.getInstance();
const queryResult = await platformService.dbQuery("SELECT * FROM logs");
allLogs = databaseUtil.mapQueryResultToValues(
const queryResult = await platformService.dbQuery(
"SELECT * FROM logs ORDER BY date DESC",
);
this.logs = databaseUtil.mapQueryResultToValues(
queryResult,
) as unknown as Log[];
if (USE_DEXIE_DB) {
await db.open();
allLogs = await db.logs.toArray();
// Sort by date in reverse chronological order
this.logs = allLogs.sort((a, b) => {
const dateA = new Date(a.date);
const dateB = new Date(b.date);
return dateB.getTime() - dateA.getTime();
});
}
// Sort by date in reverse chronological order
this.logs = allLogs.sort((a, b) => {
const dateA = new Date(a.date);
const dateB = new Date(b.date);
return dateB.getTime() - dateA.getTime();
});
} catch (error) {
logger.error("Error loading logs:", error);
this.error =

Loading…
Cancel
Save