fix logginng error
This commit is contained in:
parent
d4c6ec1ecf
commit
9fba9241dc
29
src/main.ts
29
src/main.ts
@ -9,6 +9,7 @@ import {
|
|||||||
Platform,
|
Platform,
|
||||||
TFile,
|
TFile,
|
||||||
TFolder,
|
TFolder,
|
||||||
|
requestUrl,
|
||||||
} from "obsidian";
|
} from "obsidian";
|
||||||
import cloneDeep from "lodash/cloneDeep";
|
import cloneDeep from "lodash/cloneDeep";
|
||||||
import { createElement, RotateCcw, RefreshCcw, FileText } from "lucide";
|
import { createElement, RotateCcw, RefreshCcw, FileText } from "lucide";
|
||||||
@ -479,7 +480,7 @@ export default class RemotelySavePlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// must AFTER preparing DB
|
// must AFTER preparing DB
|
||||||
this.addOutputToDBIfSet();
|
this.redirectLoggingOuputBasedOnSetting();
|
||||||
this.enableAutoClearOutputToDBHistIfSet();
|
this.enableAutoClearOutputToDBHistIfSet();
|
||||||
|
|
||||||
// must AFTER preparing DB
|
// must AFTER preparing DB
|
||||||
@ -1199,12 +1200,32 @@ export default class RemotelySavePlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addOutputToDBIfSet() {
|
redirectLoggingOuputBasedOnSetting() {
|
||||||
if (this.settings.logToDB) {
|
|
||||||
applyLogWriterInplace((...msg: any[]) => {
|
applyLogWriterInplace((...msg: any[]) => {
|
||||||
|
if (this.settings.logToDB) {
|
||||||
insertLoggerOutputByVault(this.db, this.vaultRandomID, ...msg);
|
insertLoggerOutputByVault(this.db, this.vaultRandomID, ...msg);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
if (
|
||||||
|
this.debugServerTemp !== undefined &&
|
||||||
|
this.debugServerTemp.trim().startsWith("http")
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
requestUrl({
|
||||||
|
url: this.debugServerTemp,
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
send_time: Date.now(),
|
||||||
|
log_text: msg,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
// pass
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
enableAutoClearOutputToDBHistIfSet() {
|
enableAutoClearOutputToDBHistIfSet() {
|
||||||
|
|||||||
@ -2091,17 +2091,17 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
|||||||
.setValue(this.plugin.settings.logToDB ? "enable" : "disable")
|
.setValue(this.plugin.settings.logToDB ? "enable" : "disable")
|
||||||
.onChange(async (val: string) => {
|
.onChange(async (val: string) => {
|
||||||
const logToDB = val === "enable";
|
const logToDB = val === "enable";
|
||||||
if (logToDB) {
|
// if (logToDB) {
|
||||||
applyLogWriterInplace((...msg: any[]) => {
|
// applyLogWriterInplace((...msg: any[]) => {
|
||||||
insertLoggerOutputByVault(
|
// insertLoggerOutputByVault(
|
||||||
this.plugin.db,
|
// this.plugin.db,
|
||||||
this.plugin.vaultRandomID,
|
// this.plugin.vaultRandomID,
|
||||||
...msg
|
// ...msg
|
||||||
);
|
// );
|
||||||
});
|
// });
|
||||||
} else {
|
// } else {
|
||||||
restoreLogWritterInplace();
|
// restoreLogWritterInplace();
|
||||||
}
|
// }
|
||||||
clearExpiredLoggerOutputRecords(this.plugin.db);
|
clearExpiredLoggerOutputRecords(this.plugin.db);
|
||||||
this.plugin.settings.logToDB = logToDB;
|
this.plugin.settings.logToDB = logToDB;
|
||||||
await this.plugin.saveSettings();
|
await this.plugin.saveSettings();
|
||||||
@ -2153,7 +2153,7 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
|||||||
if (logToHttpServer === "" || !logToHttpServer.startsWith("http")) {
|
if (logToHttpServer === "" || !logToHttpServer.startsWith("http")) {
|
||||||
this.plugin.debugServerTemp = "";
|
this.plugin.debugServerTemp = "";
|
||||||
logToHttpServer = "";
|
logToHttpServer = "";
|
||||||
restoreLogWritterInplace();
|
// restoreLogWritterInplace();
|
||||||
new Notice(t("settings_logtohttpserver_reset_notice"));
|
new Notice(t("settings_logtohttpserver_reset_notice"));
|
||||||
} else {
|
} else {
|
||||||
new SetLogToHttpServerModal(
|
new SetLogToHttpServerModal(
|
||||||
@ -2162,23 +2162,23 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
|
|||||||
logToHttpServer,
|
logToHttpServer,
|
||||||
() => {
|
() => {
|
||||||
this.plugin.debugServerTemp = logToHttpServer;
|
this.plugin.debugServerTemp = logToHttpServer;
|
||||||
applyLogWriterInplace((...msg: any[]) => {
|
// applyLogWriterInplace((...msg: any[]) => {
|
||||||
try {
|
// try {
|
||||||
requestUrl({
|
// requestUrl({
|
||||||
url: logToHttpServer,
|
// url: logToHttpServer,
|
||||||
method: "POST",
|
// method: "POST",
|
||||||
headers: {
|
// headers: {
|
||||||
"Content-Type": "application/json",
|
// "Content-Type": "application/json",
|
||||||
},
|
// },
|
||||||
body: JSON.stringify({
|
// body: JSON.stringify({
|
||||||
send_time: Date.now(),
|
// send_time: Date.now(),
|
||||||
log_text: msg,
|
// log_text: msg,
|
||||||
}),
|
// }),
|
||||||
});
|
// });
|
||||||
} catch (e) {
|
// } catch (e) {
|
||||||
// pass
|
// // pass
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
}
|
}
|
||||||
).open();
|
).open();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user