From f9c1660f934b8cbdad4c5de8a0280ab6064b6b37 Mon Sep 17 00:00:00 2001 From: Ole Eskild Steensen Date: Tue, 3 Oct 2023 17:08:49 +0200 Subject: [PATCH] Add logging to mobile version --- main.ts | 27 +++++++++++++++++++++++++++ manifest-beta.json | 2 +- versions.json | 1 + 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/main.ts b/main.ts index 958ae0d..e6e4af7 100644 --- a/main.ts +++ b/main.ts @@ -76,6 +76,7 @@ export default class DigitalGarden extends Plugin { publishModal!: PublicationCenter; async onload() { + this.monkeyPatchConsole(this); this.appVersion = this.manifest.version; console.log("Initializing DigitalGarden plugin v" + this.appVersion); @@ -524,4 +525,30 @@ export default class DigitalGarden extends Plugin { } this.publishModal.open(); } + + monkeyPatchConsole(plugin: Plugin) { + if (!Platform.isMobile) { + return; + } + + const logFile = `${plugin.manifest.dir}/logs.txt`; + const logs: string[] = []; + + const logMessages = + (prefix: string) => + (...messages: unknown[]) => { + logs.push(`\n[${prefix}]`); + + for (const message of messages) { + logs.push(String(message)); + } + plugin.app.vault.adapter.write(logFile, logs.join(" ")); + }; + + console.debug = logMessages("debug"); + console.error = logMessages("error"); + console.info = logMessages("info"); + console.log = logMessages("log"); + console.warn = logMessages("warn"); + } } diff --git a/manifest-beta.json b/manifest-beta.json index e823542..0746854 100644 --- a/manifest-beta.json +++ b/manifest-beta.json @@ -1,7 +1,7 @@ { "id": "digitalgarden", "name": "Digital Garden", - "version": "2.50.3", + "version": "2.50.4", "minAppVersion": "0.12.0", "description": "Publish your notes to the web for others to enjoy. For free.", "author": "Ole Eskild Steensen", diff --git a/versions.json b/versions.json index 2af9016..de851d1 100644 --- a/versions.json +++ b/versions.json @@ -1,4 +1,5 @@ { + "2.50.4": "0.12.0", "2.50.3": "0.12.0", "2.50.2": "0.12.0", "2.50.1": "0.12.0",