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