fix more of the logging & log display

This commit is contained in:
2025-05-28 20:08:09 -06:00
parent c637d39dc9
commit 01c33069c4
2 changed files with 14 additions and 13 deletions

View File

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

View File

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