forked from trent_larson/crowd-funder-for-time-pwa
fix more of the logging & log display
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 =
|
||||
|
||||
Reference in New Issue
Block a user