remove logtodb since we have remote debugging nowgit add .!

This commit is contained in:
fyears 2024-01-13 12:13:52 +08:00
parent 347c051d0c
commit 87d6e1f75f
8 changed files with 11 additions and 224 deletions

View File

@ -86,7 +86,7 @@ export interface RemotelySavePluginSettings {
syncConfigDir?: boolean;
syncUnderscoreItems?: boolean;
lang?: LangTypeAndAuto;
logToDB?: boolean;
skipSizeLargerThan?: number;
ignorePaths?: string[];
enableStatusBarInfo?: boolean;
@ -96,6 +96,11 @@ export interface RemotelySavePluginSettings {
* @deprecated
*/
vaultRandomID?: string;
/**
* @deprecated
*/
logToDB?: boolean;
}
export interface RemoteItem {

View File

@ -98,27 +98,3 @@ export const exportVaultSyncPlansToFiles = async (
});
log.info("finish exporting");
};
export const exportVaultLoggerOutputToFiles = async (
db: InternalDBs,
vault: Vault,
vaultRandomID: string
) => {
await mkdirpInVault(DEFAULT_DEBUG_FOLDER, vault);
const records = await readAllLogRecordTextsByVault(db, vaultRandomID);
let md = "";
if (records.length === 0) {
md = "No logger history found.";
} else {
md =
"Logger history found:\n\n" +
"```text\n" +
records.join("\n") +
"\n```\n";
}
const ts = Date.now();
const filePath = `${DEFAULT_DEBUG_FOLDER}${DEFAULT_LOG_HISTORY_FILE_PREFIX}${ts}.md`;
await vault.create(filePath, md, {
mtime: ts,
});
};

View File

@ -38,7 +38,6 @@
"command_startsync": "start sync",
"command_drynrun": "start sync (dry run only)",
"command_exportsyncplans_json": "export sync plans in json format",
"command_exportsyncplans_table": "export sync plans in table format",
"command_exportlogsindb": "export logs saved in db",
"statusbar_time_years": "{{time}} years",
@ -268,16 +267,6 @@
"settings_delsyncplans_desc": "Delete sync plans history in DB.",
"settings_delsyncplans_button": "Delete Sync Plans History",
"settings_delsyncplans_notice": "Sync plans history (in DB) deleted.",
"settings_logtodb": "Save Console Logs Into DB",
"settings_logtodb_desc": "Enable this to save all console logs into DB, so that we can export and read them later. Especially useful for mobile debugging. Has performance cost and may impact battery. The history is saved for at most 10000 records and 7 days old.",
"settings_logtodbexport": "Export Console Logs From DB",
"settings_logtodbexport_desc": "Export the saved console logs of this vault from DB into a new file in the folder {{&debugFolder}} .",
"settings_logtodbexport_button": "Export",
"settings_logtodbexport_notice": "Console logs of this vault from DB are exported!",
"settings_logtodbclear": "Delete All Console Logs In DB",
"settings_logtodbclear_desc": "Delete all the console logs saved inside DB. This setting applies to all saved logs for all vaults in this device.",
"settings_logtodbclear_button": "Delete",
"settings_logtodbclear_notice": "All console logs saved in DB are deleted!",
"settings_logtohttpserver": "Log To HTTP Server Temporarily",
"settings_logtohttpserver_desc": "It's very dangerous and please use the function with greate cautions!!!!! It will temporarily allow sending console loggins to HTTP server.",
"settings_logtohttpserver_reset_notice": "Already removed the setting of logging to HTTP server.",

View File

@ -267,16 +267,6 @@
"settings_delsyncplans_desc": "删除数据库里的同步计划历史。",
"settings_delsyncplans_button": "删除同步计划历史",
"settings_delsyncplans_notice": "(数据库里的)同步计划已被删除。",
"settings_logtodb": "保存终端日志到数据库",
"settings_logtodb_desc": "如果开启此设置,所有终端日志都会保存到数据,从而我们可以在之后导出和阅读它们。对于移动设备的调试较为有用。有性能成本,可能会影响电池用量。历史会保存最多 10000 条和 7 天时间。",
"settings_logtodbexport": "从数据库导出终端日志",
"settings_logtodbexport_desc": "从数据库导出本资料库的已保存的终端日志,输出到文件夹 {{&debugFolder}} 下的一个新文件内。",
"settings_logtodbexport_button": "导出",
"settings_logtodbexport_notice": "数据库内的本资料库的终端日志已导出!",
"settings_logtodbclear": "删除数据库的所有终端日志",
"settings_logtodbclear_desc": "删除数据库内的所有已保存的终端日志。本设置会影响本设备下所有资料库的所有已保存日志。",
"settings_logtodbclear_button": "删除",
"settings_logtodbclear_notice": "数据库内的所有终端日志已删除!",
"settings_logtohttpserver": "临时设定终端日志实时转发到 HTTP 服务器。",
"settings_logtohttpserver_desc": "非常危险,谨慎行动!!!!!临时设定终端日志实时转发到 HTTP 服务器。",
"settings_logtohttpserver_reset_notice": "移除了终端日志转发到 HTTP 服务器的设定。",

View File

@ -267,16 +267,6 @@
"settings_delsyncplans_desc": "刪除資料庫裡的同步計劃歷史。",
"settings_delsyncplans_button": "刪除同步計劃歷史",
"settings_delsyncplans_notice": "(資料庫裡的)同步計劃已被刪除。",
"settings_logtodb": "儲存終端日誌到資料庫",
"settings_logtodb_desc": "如果開啟此設定,所有終端日誌都會儲存到資料,從而我們可以在之後匯出和閱讀它們。對於移動裝置的除錯較為有用。有效能成本,可能會影響電池用量。歷史會儲存最多 10000 條和 7 天時間。",
"settings_logtodbexport": "從資料庫匯出終端日誌",
"settings_logtodbexport_desc": "從資料庫匯出本資料庫的已儲存的終端日誌,輸出到資料夾 {{&debugFolder}} 下的一個新檔案內。",
"settings_logtodbexport_button": "匯出",
"settings_logtodbexport_notice": "資料庫內的本資料庫的終端日誌已匯出!",
"settings_logtodbclear": "刪除資料庫的所有終端日誌",
"settings_logtodbclear_desc": "刪除資料庫內的所有已儲存的終端日誌。本設定會影響本裝置下所有資料庫的所有已儲存日誌。",
"settings_logtodbclear_button": "刪除",
"settings_logtodbclear_notice": "資料庫內的所有終端日誌已刪除!",
"settings_logtohttpserver": "臨時設定終端日誌實時轉發到 HTTP 伺服器。",
"settings_logtohttpserver_desc": "非常危險,謹慎行動!!!!!臨時設定終端日誌實時轉發到 HTTP 伺服器。",
"settings_logtohttpserver_reset_notice": "移除了終端日誌轉發到 HTTP 伺服器的設定。",

View File

@ -674,67 +674,9 @@ export const readAllLogRecordTextsByVault = async (
}
};
export const insertLoggerOutputByVault = async (
db: InternalDBs,
vaultRandomID: string,
...msg: any[]
) => {
const ts = Date.now();
const tsFmt = unixTimeToStr(ts);
const key = `${vaultRandomID}\t${ts}`;
try {
const val = [`[${tsFmt}]`, ...msg.map((x) => toText(x))].join(" ");
db.loggerOutputTbl.setItem(key, val);
} catch (err) {
// give up, and let it pass
}
};
export const clearAllLoggerOutputRecords = async (db: InternalDBs) => {
await db.loggerOutputTbl.clear();
};
/**
* We remove records that are older than 7 days or 10000 records.
* It's a heavy operation, so we shall not place it in the start up.
* @param db
*/
export const clearExpiredLoggerOutputRecords = async (db: InternalDBs) => {
const MILLISECONDS_OLD = 1000 * 60 * 60 * 24 * 7; // 7 days
const COUNT_TO_MANY = 10000;
const currTs = Date.now();
const expiredTs = currTs - MILLISECONDS_OLD;
let records = (await db.loggerOutputTbl.keys()).map((key) => {
const ts = parseInt(key.split("\t")[1]);
const expired = ts <= expiredTs;
return {
ts: ts,
key: key,
expired: expired,
};
});
const keysToRemove = new Set(
records.filter((x) => x.expired).map((x) => x.key)
);
if (records.length - keysToRemove.size > COUNT_TO_MANY) {
// we need to find out records beyond 10000 records
records = records.filter((x) => !x.expired); // shrink the array
records.sort((a, b) => -(a.ts - b.ts)); // descending
records.slice(COUNT_TO_MANY).forEach((element) => {
keysToRemove.add(element.key);
});
}
const ps = [] as Promise<void>[];
keysToRemove.forEach((element) => {
ps.push(db.loggerOutputTbl.removeItem(element));
});
await Promise.all(ps);
log.debug(`successfully clearAllLoggerOutputRecords`);
};
export const upsertLastSuccessSyncByVault = async (

View File

@ -33,12 +33,11 @@ import {
loadFileHistoryTableByVault,
prepareDBs,
InternalDBs,
insertLoggerOutputByVault,
clearExpiredLoggerOutputRecords,
clearExpiredSyncPlanRecords,
upsertLastSuccessSyncByVault,
getLastSuccessSyncByVault,
upsertPluginVersionByVault,
clearAllLoggerOutputRecords,
} from "./localdb";
import { RemoteClient } from "./remote";
import {
@ -70,7 +69,6 @@ import { applyPresetRulesInplace } from "./presetRules";
import { applyLogWriterInplace, log } from "./moreOnLog";
import AggregateError from "aggregate-error";
import {
exportVaultLoggerOutputToFiles,
exportVaultSyncPlansToFiles,
} from "./debugMode";
import { SizesConflictModal } from "./syncSizesConflictNotice";
@ -795,35 +793,6 @@ export default class RemotelySavePlugin extends Plugin {
},
});
this.addCommand({
id: "export-sync-plans-table",
name: t("command_exportsyncplans_table"),
icon: iconNameLogs,
callback: async () => {
await exportVaultSyncPlansToFiles(
this.db,
this.app.vault,
this.vaultRandomID,
"table"
);
new Notice(t("settings_syncplans_notice"));
},
});
this.addCommand({
id: "export-logs-in-db",
name: t("command_exportlogsindb"),
icon: iconNameLogs,
callback: async () => {
await exportVaultLoggerOutputToFiles(
this.db,
this.app.vault,
this.vaultRandomID
);
new Notice(t("settings_logtodbexport_notice"));
},
});
this.addSettingTab(new RemotelySaveSettingTab(this.app, this));
// this.registerDomEvent(document, "click", (evt: MouseEvent) => {
@ -910,6 +879,7 @@ export default class RemotelySavePlugin extends Plugin {
if (this.settings.deleteToWhere === undefined) {
this.settings.deleteToWhere = "system";
}
this.settings.logToDB = false; // deprecated as of 20240113
}
async checkIfPresetRulesFollowed() {
@ -1228,9 +1198,6 @@ export default class RemotelySavePlugin extends Plugin {
redirectLoggingOuputBasedOnSetting() {
applyLogWriterInplace((...msg: any[]) => {
if (this.settings.logToDB) {
insertLoggerOutputByVault(this.db, this.vaultRandomID, ...msg);
}
if (
this.debugServerTemp !== undefined &&
this.debugServerTemp.trim().startsWith("http")
@ -1255,24 +1222,13 @@ export default class RemotelySavePlugin extends Plugin {
}
enableAutoClearOutputToDBHistIfSet() {
const initClearOutputToDBHistAfterMilliseconds = 1000 * 45;
const autoClearOutputToDBHistAfterMilliseconds = 1000 * 60 * 5;
const initClearOutputToDBHistAfterMilliseconds = 1000 * 30;
this.app.workspace.onLayoutReady(() => {
// init run
window.setTimeout(() => {
if (this.settings.logToDB) {
clearExpiredLoggerOutputRecords(this.db);
}
clearAllLoggerOutputRecords(this.db);
}, initClearOutputToDBHistAfterMilliseconds);
// scheduled run
const intervalID = window.setInterval(() => {
if (this.settings.logToDB) {
clearExpiredLoggerOutputRecords(this.db);
}
}, autoClearOutputToDBHistAfterMilliseconds);
this.registerInterval(intervalID);
});
}

View File

@ -21,16 +21,12 @@ import {
} from "./baseTypes";
import {
exportVaultSyncPlansToFiles,
exportVaultLoggerOutputToFiles,
} from "./debugMode";
import { exportQrCodeUri } from "./importExport";
import {
clearAllSyncMetaMapping,
clearAllSyncPlanRecords,
destroyDBs,
clearAllLoggerOutputRecords,
insertLoggerOutputByVault,
clearExpiredLoggerOutputRecords,
upsertLastSuccessSyncByVault,
} from "./localdb";
import type RemotelySavePlugin from "./main"; // unavoidable
@ -2069,63 +2065,6 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
});
});
new Setting(debugDiv)
.setName(t("settings_logtodb"))
.setDesc(t("settings_logtodb_desc"))
.addDropdown(async (dropdown) => {
dropdown.addOption("enable", t("enable"));
dropdown.addOption("disable", t("disable"));
dropdown
.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();
// }
clearExpiredLoggerOutputRecords(this.plugin.db);
this.plugin.settings.logToDB = logToDB;
await this.plugin.saveSettings();
});
});
new Setting(debugDiv)
.setName(t("settings_logtodbexport"))
.setDesc(
t("settings_logtodbexport_desc", {
debugFolder: DEFAULT_DEBUG_FOLDER,
})
)
.addButton(async (button) => {
button.setButtonText(t("settings_logtodbexport_button"));
button.onClick(async () => {
await exportVaultLoggerOutputToFiles(
this.plugin.db,
this.app.vault,
this.plugin.vaultRandomID
);
new Notice(t("settings_logtodbexport_notice"));
});
});
new Setting(debugDiv)
.setName(t("settings_logtodbclear"))
.setDesc(t("settings_logtodbclear_desc"))
.addButton(async (button) => {
button.setButtonText(t("settings_logtodbclear_button"));
button.onClick(async () => {
await clearAllLoggerOutputRecords(this.plugin.db);
new Notice(t("settings_logtodbclear_notice"));
});
});
let logToHttpServer = this.plugin.debugServerTemp || "";
new Setting(debugDiv)
.setName(t("settings_logtohttpserver"))